Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 55 additions & 0 deletions src/handler/manager/checkMatchExists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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
.union([z.literal("true"), z.literal("false"), z.boolean()])
.transform((value) => value === true || value === "true"),
})
.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.ELIMINATION
: MatchType.QUALIFICATION,
},
});

if (match !== null) {
res.status(200).send({
match,
alliance: Number(match.key.at(-1)) < 3 ? "red" : "blue",
});
return;
}
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.
};
42 changes: 41 additions & 1 deletion src/routes/manager/manager.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ import { getTeamTournamentStatus } from "../../handler/manager/getTeamTournament
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 { checkMatchExists } from "../../handler/manager/checkMatchExists.js";

const router = Router();

Expand Down Expand Up @@ -126,6 +131,39 @@ registry.registerPath({
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
.union([z.literal("true"), z.literal("false"), z.boolean()])
.transform((value) => value === true || value === "true"),
}),
Comment thread
Copilot marked this conversation as resolved.
Comment thread
Copilot marked this conversation as resolved.
},
responses: {
200: {
description: "Match data row and alliance",
content: {
"application/json": {
schema: z.object({
match: TeamMatchDataSchema,
alliance: z.string(),
}),
},
},
},
400: { description: "Invalid parameters" },
404: { description: "Match not found" },
},
security: [],
});
Comment thread
jackattack-4 marked this conversation as resolved.

// Profile
const ProfileSchema = z.object({
id: z.string(),
Expand Down Expand Up @@ -418,6 +456,8 @@ router.use("/apikey", apikey);
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