feat : fix a lot of stuff
This commit is contained in:
@@ -64,13 +64,39 @@ export const handler: Handlers = {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { note } = body;
|
||||
const { note, noteSession2 } = body;
|
||||
|
||||
if (note === undefined) {
|
||||
return new Response("Champ 'note' manquant", { status: 400 });
|
||||
if (note === undefined && noteSession2 === undefined) {
|
||||
return new Response("Au moins 'note' ou 'noteSession2' requis", {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const result = await db.update(notes).set({ note }).where(
|
||||
if (
|
||||
note !== undefined &&
|
||||
(typeof note !== "number" || note < 0 || note > 20)
|
||||
) {
|
||||
return new Response("Champ 'note' doit être un nombre entre 0 et 20", {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
noteSession2 !== undefined && noteSession2 !== null &&
|
||||
(typeof noteSession2 !== "number" || noteSession2 < 0 ||
|
||||
noteSession2 > 20)
|
||||
) {
|
||||
return new Response(
|
||||
"Champ 'noteSession2' doit être un nombre entre 0 et 20",
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const set: { note?: number; noteSession2?: number | null } = {};
|
||||
if (note !== undefined) set.note = note;
|
||||
if (noteSession2 !== undefined) set.noteSession2 = noteSession2;
|
||||
|
||||
const result = await db.update(notes).set(set).where(
|
||||
and(
|
||||
eq(notes.numEtud, numEtud),
|
||||
eq(notes.idModule, idModule),
|
||||
|
||||
@@ -26,20 +26,38 @@ export const handler: Handlers = {
|
||||
const rows = XLSX.utils.sheet_to_json(sheet) as {
|
||||
numEtud: number;
|
||||
note: number;
|
||||
noteSession2?: number;
|
||||
}[];
|
||||
|
||||
for (const row of rows) {
|
||||
const { numEtud, note } = row;
|
||||
const { numEtud, note, noteSession2 } = row;
|
||||
|
||||
if (!numEtud || note === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const values: {
|
||||
numEtud: number;
|
||||
idModule: string;
|
||||
note: number;
|
||||
noteSession2?: number | null;
|
||||
} = {
|
||||
numEtud,
|
||||
idModule,
|
||||
note,
|
||||
};
|
||||
const set: { note: number; noteSession2?: number | null } = { note };
|
||||
|
||||
if (noteSession2 !== undefined) {
|
||||
values.noteSession2 = noteSession2;
|
||||
set.noteSession2 = noteSession2;
|
||||
}
|
||||
|
||||
await db.insert(notes)
|
||||
.values({ numEtud, idModule, note })
|
||||
.values(values)
|
||||
.onConflictDoUpdate({
|
||||
target: [notes.numEtud, notes.idModule],
|
||||
set: { note },
|
||||
set,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user