feat : fix a lot of stuff
This commit is contained in:
@@ -52,8 +52,12 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
||||
}
|
||||
|
||||
try {
|
||||
const body: { numEtud: number; idUE: number; valeur: number } =
|
||||
await request.json();
|
||||
const body: {
|
||||
numEtud: number;
|
||||
idUE: number;
|
||||
valeur: number;
|
||||
malus?: number;
|
||||
} = await request.json();
|
||||
|
||||
if (!body.numEtud || !body.idUE || body.valeur === undefined) {
|
||||
return new Response(
|
||||
@@ -62,12 +66,23 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
body.malus !== undefined &&
|
||||
(!Number.isInteger(body.malus) || body.malus < 0)
|
||||
) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: "malus doit être un entier >= 0" }),
|
||||
{ status: 400, headers: { "content-type": "application/json" } },
|
||||
);
|
||||
}
|
||||
|
||||
const [created] = await db
|
||||
.insert(ajustements)
|
||||
.values({
|
||||
numEtud: body.numEtud,
|
||||
idUE: body.idUE,
|
||||
valeur: body.valeur,
|
||||
malus: body.malus ?? 0,
|
||||
})
|
||||
.returning();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user