added deleteParticipant

This commit is contained in:
Laurin
2022-05-29 01:14:47 +02:00
parent 4bec0d4b5e
commit b1a0e8be7c
2 changed files with 20 additions and 2 deletions
+19 -1
View File
@@ -74,7 +74,7 @@ export const createParticipant = async (req: Request<{ pid: string}>, res: Respo
}
}
const updateParticipant = async (req: Request<{ pid: string }>, res: Response) => {
export const updateParticipant = async (req: Request<{ pid: string }>, res: Response) => {
//insert TeamleaderAuth
const result = updateParticipantBody.safeParse(req.body);
@@ -138,3 +138,21 @@ const updateParticipant = async (req: Request<{ pid: string }>, res: Response) =
throw e;
}
}
export const deleteParticipant = async (req: Request<{ pid: string }>, res: Response) => {
//insert TeamleaderAuth
const { pid } = req.params;
try {
await prisma.participant.delete({ where: { pid } });
return res.status(204).end();
} catch (e) {
if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") {
return res.status(404).json(generateError(`The participant with the ID ${pid} could not be found`));
}
throw e;
}
}