Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/handler/manager/checkMatchExists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import z from "zod";
import { addTournamentMatches } from "./addTournamentMatches.js";
import { Request, Response } from "express";
import prismaClient from "../../prismaClient.js";
import { MatchType } from "@prisma/client";

export const checkMatchExists = async (
req: Request,
res: Response,
): Promise<void> => {
try {
const parsed = z
.object({
tournamentKey: z.string(),
teamNumber: z.coerce.number().int(),
matchNumber: z.coerce.number().int(),
isElim: z.coerce.boolean(),
})
Comment thread
jackattack-4 marked this conversation as resolved.
.safeParse(req.query);

if (!parsed.success) {
res.status(400).send(parsed.error.flatten());
return;
}

const params = parsed.data;

await addTournamentMatches(params.tournamentKey);

const match = await prismaClient.teamMatchData.findFirst({
where: {
matchNumber: params.matchNumber,
tournamentKey: params.tournamentKey,
teamNumber: params.teamNumber,
matchType: params.isElim
? MatchType.QUALIFICATION
: MatchType.ELIMINATION,
Comment thread
jackattack-4 marked this conversation as resolved.
Outdated
},
});

if (match !== null) {
res
.status(200)
.send({ match, alliance: Number(match.key[-1]) < 3 ? "RED" : "BLUE" });
return;
Comment thread
jackattack-4 marked this conversation as resolved.
Outdated
}
res.status(404).send("MATCH_NOT_FOUND");
} catch (error) {
console.log(error);
res.status(500).send(error);
}
Comment thread
jackattack-4 marked this conversation as resolved.
};
36 changes: 35 additions & 1 deletion src/routes/manager/manager.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@
import { getMatchResults } from "../../handler/manager/getMatchResults.js";
import { registry } from "../../lib/openapi.js";
import { z } from "zod";
import { TeamSchema, TournamentSchema } from "../../lib/prisma-zod.js";
import {
TeamMatchDataSchema,
TeamSchema,
TournamentSchema,
} from "../../lib/prisma-zod.js";
import { requireVerifiedTeam } from "../../lib/middleware/requireVerifiedTeam.js";
import { MatchType } from "@prisma/client";

Check failure on line 38 in src/routes/manager/manager.routes.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'MatchType' is defined but never used
Comment thread
jackattack-4 marked this conversation as resolved.
Outdated
import { checkMatchExists } from "../../handler/manager/checkMatchExists.js";

const router = Router();

Expand Down Expand Up @@ -126,6 +132,32 @@
security: [{ bearerAuth: [] }],
});

registry.registerPath({
method: "get",
path: "/v1/manager/checkmatch",
tags: ["Manager - Matches"],
summary: "Check if a match exists and if a team is in the match",
request: {
query: z.object({
tournamentKey: z.string(),
teamNumber: z.coerce.number().int(),
matchNumber: z.coerce.number().int(),
isElim: z.coerce.boolean(),
}),
Comment thread
Copilot marked this conversation as resolved.
Comment thread
Copilot marked this conversation as resolved.
},
responses: {
200: {
description: "Match Data Row (or null if not found)",
Comment thread
Copilot marked this conversation as resolved.
Outdated
content: {
"application/json": { schema: TeamMatchDataSchema.nullable() },
},
},
400: { description: "Invalid parameters" },
401: { description: "Unauthorized" },
},
Comment thread
Copilot marked this conversation as resolved.
security: [],
});
Comment thread
jackattack-4 marked this conversation as resolved.
Comment thread
jackattack-4 marked this conversation as resolved.

// Profile
const ProfileSchema = z.object({
id: z.string(),
Expand Down Expand Up @@ -418,6 +450,8 @@
router.get("/teams", requireAuth, getTeams);
router.get("/tournaments", requireAuth, getTournaments);

router.get("/checkmatch", checkMatchExists);
Comment thread
jackattack-4 marked this conversation as resolved.
Comment thread
jackattack-4 marked this conversation as resolved.
Comment thread
jackattack-4 marked this conversation as resolved.

router.get(
"/matches/:tournament",
requireAuth,
Expand Down
Loading