From b1a0e8be7c96e8a7c4494739d87f255477c907c3 Mon Sep 17 00:00:00 2001 From: Laurin <60652077+Flexla54@users.noreply.github.com> Date: Sun, 29 May 2022 01:14:47 +0200 Subject: [PATCH] added deleteParticipant --- src/Controllers/event.controller.ts | 2 +- src/Controllers/participant.controller.ts | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Controllers/event.controller.ts b/src/Controllers/event.controller.ts index 3193c37..42706f3 100644 --- a/src/Controllers/event.controller.ts +++ b/src/Controllers/event.controller.ts @@ -241,7 +241,7 @@ export const deleteEvent = async (req: Request, res: Res return res.status(204).end(); } catch (e) { if (e instanceof PrismaClientKnownRequestError && e.code === "P2025") { - return res.status(404).json(generateError(`The organisation with the ID ${pid} could not be found`)); + return res.status(404).json(generateError(`The event with the ID ${pid} could not be found`)); } throw e; diff --git a/src/Controllers/participant.controller.ts b/src/Controllers/participant.controller.ts index 9eb0047..54f4b18 100644 --- a/src/Controllers/participant.controller.ts +++ b/src/Controllers/participant.controller.ts @@ -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; + } +} \ No newline at end of file