From b29b0cd19ad47e43545390d8b8dbbfc81fe4cb6d Mon Sep 17 00:00:00 2001 From: Anys Date: Thu, 23 Apr 2026 10:53:39 +0200 Subject: [PATCH] feat(api): implement ajustement delete endpoint - DELETE /ajustements/{numEtud}/{idUE}: remove ajustement from DB - Requires employee role - Returns 204 on success --- .../notes/api/ajustements/[numEtud]/[idUE].ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/routes/(apps)/notes/api/ajustements/[numEtud]/[idUE].ts b/routes/(apps)/notes/api/ajustements/[numEtud]/[idUE].ts index ae7232c..25a645a 100644 --- a/routes/(apps)/notes/api/ajustements/[numEtud]/[idUE].ts +++ b/routes/(apps)/notes/api/ajustements/[numEtud]/[idUE].ts @@ -40,4 +40,30 @@ export const handler: Handlers = { headers: { "content-type": "application/json" }, }); }, + + // #52 DELETE /ajustements/{numEtud}/{idUE} + async DELETE( + _request: Request, + context: FreshContext, + ): Promise { + if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { + return FORBIDDEN; + } + + const numEtud = Number(context.params.numEtud); + const idUE = Number(context.params.idUE); + + if (isNaN(numEtud) || isNaN(idUE)) { + return new Response("Paramètres invalides", { status: 400 }); + } + + const [deleted] = await db + .delete(ajustements) + .where(eq(ajustements.numEtud, numEtud), eq(ajustements.idUE, idUE)) + .returning(); + + if (!deleted) return NOT_FOUND; + + return new Response(null, { status: 204 }); + }, };