fixed inconsitencies with NotFoundError

This commit is contained in:
Laurin
2023-01-02 18:56:12 +01:00
committed by La_Felx
parent c190e319a0
commit cf20f11ec1
8 changed files with 42 additions and 61 deletions
+12 -5
View File
@@ -137,8 +137,17 @@ export const createParticipant = async (req: Request<{ teamPid: string }>, res:
const maxteamsize = discipline?.discipline.maxTeamSize;
const userCount = await prisma.participant.count({
where: { team: { pid: teamPid } },
const roles = await prisma.team.findUnique({
where: { pid: teamPid },
select: { roles: true },
});
let userCount: number = 0;
roles?.roles.forEach((role) => {
if (role.participantId !== null) {
userCount++;
}
});
if (maxteamsize == userCount) {
@@ -159,9 +168,7 @@ export const createParticipant = async (req: Request<{ teamPid: string }>, res:
return res.status(201).json({ type: "success", payload: { participant } });
} catch (e) {
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
return res
.status(404)
.json(generateError(`Could not link to team with ID '${teamPid}, or group with ID ${body.groupPid}'`));
throw new NotFoundError("team", teamPid);
}
throw e;
}