refactor(notes): improve error handling and formatting
docs: update CLAUDE.md formatting
This commit is contained in:
@@ -34,28 +34,30 @@ export const handler: Handlers = {
|
||||
}),
|
||||
|
||||
// #43 POST /notes
|
||||
POST: withRules(["note_write", "own_teaching_note"])(async (request, _context) => {
|
||||
const body = await request.json();
|
||||
const { note, numEtud, idModule } = body;
|
||||
POST: withRules(["note_write", "own_teaching_note"])(
|
||||
async (request, _context) => {
|
||||
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,
|
||||
if (note === undefined || !numEtud || !idModule) {
|
||||
return new Response("Champs 'note', 'numEtud' et 'idModule' requis", {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof note !== "number" || note < 0 || note > 20) {
|
||||
return new Response("Champ 'note' doit être un nombre entre 0 et 20", {
|
||||
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" },
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof note !== "number" || note < 0 || note > 20) {
|
||||
return new Response("Champ 'note' doit être un nombre entre 0 et 20", {
|
||||
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" },
|
||||
});
|
||||
}),
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user