From 79669d60cf41e649fd244494128771f1284ae3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Oudelet?= Date: Wed, 22 Apr 2026 18:11:53 +0200 Subject: [PATCH] =?UTF-8?q?PMPR-38=20:=20POST=20/ue-modules=20-=20associer?= =?UTF-8?q?=20un=20module=20=C3=A0=20une=20UE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/(apps)/notes/api/ue-modules.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/routes/(apps)/notes/api/ue-modules.ts b/routes/(apps)/notes/api/ue-modules.ts index 17ae928..ba56b66 100644 --- a/routes/(apps)/notes/api/ue-modules.ts +++ b/routes/(apps)/notes/api/ue-modules.ts @@ -33,4 +33,26 @@ export const handler: Handlers = { return new Response("Failed to fetch data", { status: 500 }); } }, + + // #38 POST /ue-modules + async POST(request) { + try { + const body = await request.json(); + const { idModule, idUE, idPromo, coeff } = body; + + if (!idModule || !idUE || !idPromo || coeff === undefined) { + return new Response("Champs 'idModule', 'idUE', 'idPromo' et 'coeff' requis", { status: 400 }); + } + + const result = await db.insert(ueModules).values({ idModule, idUE, idPromo, coeff }).returning(); + + return new Response(JSON.stringify(result[0]), { + status: 201, + headers: { "Content-Type": "application/json" }, + }); + } catch (error) { + console.error("Error creating UE-module:", error); + return new Response("Failed to create UE-module", { status: 500 }); + } + }, }; \ No newline at end of file