Skip to content

Commit

Permalink
feat: migrate script
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavilien committed Feb 8, 2025
1 parent b37ca7a commit 1e9492c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/controllers/JudgeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export async function getJudges(req: Request, res: Response): Promise<void> {
// Make judges from a list of emails
export async function makeJudges(req: Request, res: Response): Promise<void> {
const emails = req.body as string[];
console.log(0);
console.log(emails);
if (!Array.isArray(emails)) {
console.log(1);
return bad(res, "Request body should be an array of emails!");
}
console.log(2);

await User.updateMany(
{
Expand All @@ -37,6 +41,27 @@ export async function makeJudges(req: Request, res: Response): Promise<void> {
judge: true,
}
);
console.log(3);

res.status(200).send();
}

export async function removeJudges(req: Request, res: Response): Promise<void> {
const emails = req.body as string[];
if (!Array.isArray(emails)) {
return bad(res, "Request body should be an array of emails!");
}

await User.updateMany(
{
email: {
$in: emails,
},
},
{
judge: false,
}
);

res.status(200).send();
}
37 changes: 36 additions & 1 deletion src/routes/judge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import express, { Router } from "express";
import { getJudges, makeJudges } from "../controllers/JudgeController";
import {
getJudges,
makeJudges,
removeJudges,
} from "../controllers/JudgeController";
import { asyncCatch } from "../util/asyncCatch";
import { isAdmin } from "./middleware";

Expand Down Expand Up @@ -66,4 +70,35 @@ router.get("/", isAdmin, asyncCatch(getJudges));
*/
router.post("/", isAdmin, asyncCatch(makeJudges));

/**
* @swagger
* /judges/remove:
* post:
* summary: Remove many judges from a list of emails
* tags: [Judge Module]
* description: Remove a list of users (emails) from judges. Access - Admin only
* security:
* - apiKeyAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: array
* items:
* type: string
* responses:
* 200:
* description: Success.
* 400:
* description: Bad request
* 403:
* description: Unauthorized.
* 404:
* description: User does not exist.
* 500:
* description: Internal Server Error.
*/
router.post("/remove", isAdmin, asyncCatch(removeJudges));

export default router;

0 comments on commit 1e9492c

Please sign in to comment.