diff --git a/routes/(apps)/notes/api/notes.ts b/routes/(apps)/notes/api/notes.ts index 385caaa..0dcdf39 100644 --- a/routes/(apps)/notes/api/notes.ts +++ b/routes/(apps)/notes/api/notes.ts @@ -36,4 +36,26 @@ export const handler: Handlers = { return new Response("Failed to fetch data", { status: 500 }); } }, + + // #43 POST /notes + async POST(request) { + try { + const body = await request.json(); + const { note, numEtud, idModule } = body; + + if (note === undefined || !numEtud || !idModule) { + return new Response("Champs 'note', 'numEtud' et 'idModule' requis", { status: 400 }); + } + + const result = await db.insert(notes).values({ note, numEtud, idModule }).returning(); + + return new Response(JSON.stringify(result[0]), { + status: 201, + headers: { "Content-Type": "application/json" }, + }); + } catch (error) { + console.error("Error creating note:", error); + return new Response("Failed to create note", { status: 500 }); + } + }, }; \ No newline at end of file