refactor(notes): improve error handling and formatting
docs: update CLAUDE.md formatting
This commit is contained in:
@@ -34,7 +34,8 @@ export const handler: Handlers = {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
// #43 POST /notes
|
// #43 POST /notes
|
||||||
POST: withRules(["note_write", "own_teaching_note"])(async (request, _context) => {
|
POST: withRules(["note_write", "own_teaching_note"])(
|
||||||
|
async (request, _context) => {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { note, numEtud, idModule } = body;
|
const { note, numEtud, idModule } = body;
|
||||||
|
|
||||||
@@ -57,5 +58,6 @@ export const handler: Handlers = {
|
|||||||
status: 201,
|
status: 201,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
});
|
});
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import { and, eq } from "npm:drizzle-orm@0.45.2";
|
|||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
// #45 GET /notes/:numEtud/:idModule
|
// #45 GET /notes/:numEtud/:idModule
|
||||||
GET: withRules(["note_read", "own_note", "own_teaching_note"])(async (_request, context) => {
|
GET: withRules(["note_read", "own_note", "own_teaching_note"])(
|
||||||
|
async (_request, context) => {
|
||||||
try {
|
try {
|
||||||
const numEtud = parseInt(context.params.numEtud);
|
const numEtud = parseInt(context.params.numEtud);
|
||||||
const { idModule } = context.params;
|
const { idModule } = context.params;
|
||||||
@@ -47,11 +48,11 @@ export const handler: Handlers = {
|
|||||||
return new Response("Failed to fetch data", { status: 500 });
|
return new Response("Failed to fetch data", { status: 500 });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
),
|
||||||
}),
|
|
||||||
|
|
||||||
// #46 PUT /notes/:numEtud/:idModule
|
// #46 PUT /notes/:numEtud/:idModule
|
||||||
PUT: withRules(["note_write", "own_teaching_note"])(async (request, context) => {
|
PUT: withRules(["note_write", "own_teaching_note"])(
|
||||||
|
async (request, context) => {
|
||||||
try {
|
try {
|
||||||
const numEtud = parseInt(context.params.numEtud);
|
const numEtud = parseInt(context.params.numEtud);
|
||||||
const { idModule } = context.params;
|
const { idModule } = context.params;
|
||||||
@@ -99,8 +100,7 @@ export const handler: Handlers = {
|
|||||||
return new Response("Failed to update note", { status: 500 });
|
return new Response("Failed to update note", { status: 500 });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
),
|
||||||
}),
|
|
||||||
|
|
||||||
// #47 DELETE /notes/:numEtud/:idModule
|
// #47 DELETE /notes/:numEtud/:idModule
|
||||||
DELETE: withRules(["note_write"])(async (_request, context) => {
|
DELETE: withRules(["note_write"])(async (_request, context) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user