PMPR-43 : POST /notes - créer une note

This commit was merged in pull request #117.
This commit is contained in:
Clément Oudelet
2026-04-22 18:01:35 +02:00
committed by djalim
parent a19a1e6c13
commit 96b7edf77f
+22
View File
@@ -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 });
}
},
};