fix: correct handler bugs exposed by test suite
- ajustements [numEtud]/[idUE]: fix .where() missing and() — PUT/DELETE were applying only numEtud condition, modifying all rows for a student - modules/users/enseignements POST: add try/catch, return 500 on invalid JSON - modules/[idModule] PUT: add try/catch + type check on nom (string required) - modules POST: add .trim() check to reject whitespace-only id/nom - users POST: add .trim() check to reject whitespace-only id/nom/prenom - ues POST: add .trim() check to reject whitespace-only nom - notes POST: add type check (typeof number) and bounds check (0 ≤ note ≤ 20) - ue-modules POST: add coeff >= 0 validation Update robustness tests to reflect fixed behavior (remove [BUG] labels, replace assertRejects with status code assertions).
This commit is contained in:
@@ -26,11 +26,12 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
||||
return FORBIDDEN;
|
||||
}
|
||||
|
||||
const body: {
|
||||
idProf: string;
|
||||
idModule: string;
|
||||
idPromo: string;
|
||||
} = await request.json();
|
||||
let body: { idProf: string; idModule: string; idPromo: string };
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return new Response(null, { status: 500 });
|
||||
}
|
||||
|
||||
if (!body.idProf || !body.idModule || !body.idPromo) {
|
||||
return new Response(null, { status: 400 });
|
||||
|
||||
@@ -31,9 +31,14 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
||||
return new Response(null, { status: 403 });
|
||||
}
|
||||
|
||||
const body: { id: string; nom: string } = await request.json();
|
||||
let body: { id: string; nom: string };
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return new Response(null, { status: 500 });
|
||||
}
|
||||
|
||||
if (!body.id || !body.nom) {
|
||||
if (!body.id || !body.id.trim() || !body.nom || !body.nom.trim()) {
|
||||
return new Response(null, { status: 400 });
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,16 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
||||
request: Request,
|
||||
context: FreshContext<AuthenticatedState>,
|
||||
): Promise<Response> {
|
||||
const body: { nom: string } = await request.json();
|
||||
let body: { nom: string };
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return new Response(null, { status: 500 });
|
||||
}
|
||||
|
||||
if (typeof body.nom !== "string") {
|
||||
return new Response(null, { status: 400 });
|
||||
}
|
||||
|
||||
const [updated] = await db
|
||||
.update(modules)
|
||||
|
||||
@@ -27,10 +27,17 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
||||
request: Request,
|
||||
_context: FreshContext<AuthenticatedState>,
|
||||
): Promise<Response> {
|
||||
const body: { id: string; nom: string; prenom: string; idRole: number } =
|
||||
await request.json();
|
||||
let body: { id: string; nom: string; prenom: string; idRole: number };
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return new Response(null, { status: 500 });
|
||||
}
|
||||
|
||||
if (!body.id || !body.nom || !body.prenom) {
|
||||
if (
|
||||
!body.id || !body.id.trim() || !body.nom || !body.nom.trim() ||
|
||||
!body.prenom || !body.prenom.trim()
|
||||
) {
|
||||
return new Response(null, { status: 400 });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user