From b6cf9421c6b7a3982610d136a552e154abe73195 Mon Sep 17 00:00:00 2001 From: Jonas Simoen Date: Fri, 1 Mar 2024 19:02:39 +0100 Subject: [PATCH] feat: limit transfers --- src/controllers/Team.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/controllers/Team.ts b/src/controllers/Team.ts index 2798557..34c6a19 100644 --- a/src/controllers/Team.ts +++ b/src/controllers/Team.ts @@ -270,6 +270,17 @@ export const PostTransfersTeamHandler = async (req: any, rep: any) => { const remainingWeekIds = Array.from(Array(lastWeekId - weekId + 1).keys()).map(x => x + weekId); if (transfers) { + const alreadyPerformedTransfers = await prisma.transfer.findMany({ + where: { + teamId: +req.params.id, + weekId, + } + }); + + if(process.env.MAX_TRANSFERS && (transfers.length + alreadyPerformedTransfers.length) > +process.env.MAX_TRANSFERS) { + rep.status(403).send({ msg: "Whoaaa, too much transfers!" }); + return; + } const transferCreateInput = transfers.map((transfer: any) => { return { teamId: +req.params.id,