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