From d1c41ea1bddfda76352c8b8ed9d10a75dedce8a6 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Tue, 14 Oct 2025 12:25:09 -0400 Subject: [PATCH] fix(seeders): fix holiday bank_code and week_start logics to match Sunday to Saturday --- prisma/mock-seeds-scripts/09-timesheets.ts | 30 ++++++++++++---------- prisma/mock-seeds-scripts/10-shifts.ts | 4 +-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/prisma/mock-seeds-scripts/09-timesheets.ts b/prisma/mock-seeds-scripts/09-timesheets.ts index f926fb2..00523f8 100644 --- a/prisma/mock-seeds-scripts/09-timesheets.ts +++ b/prisma/mock-seeds-scripts/09-timesheets.ts @@ -6,17 +6,19 @@ const prisma = new PrismaClient(); const PREVIOUS_WEEKS = 16; // nombre de semaines à créer (passé) const INCLUDE_CURRENT = false; // true si tu veux aussi la semaine courante -// Lundi (UTC) de la semaine courante -function mondayOfThisWeekUTC(now = new Date()) { +// Dimanche (UTC) de la semaine courante +function sundayOfThisWeekUTC(now = new Date()) { + // normalise à minuit UTC du jour courant const d = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())); - const day = d.getUTCDay(); // 0=Dim, 1=Lun, ... - const diffToMonday = (day + 6) % 7; // 0 si lundi - d.setUTCDate(d.getUTCDate() - diffToMonday); + const day = d.getUTCDay(); // 0=Dim, 1=Lun, ... 6=Sam + // recule jusqu'au dimanche de cette semaine + d.setUTCDate(d.getUTCDate() - day); d.setUTCHours(0, 0, 0, 0); return d; } -function mondayNWeeksBefore(monday: Date, n: number) { - const d = new Date(monday); + +function sundayNWeeksBefore(sunday: Date, n: number) { + const d = new Date(sunday); d.setUTCDate(d.getUTCDate() - n * 7); return d; } @@ -28,21 +30,21 @@ async function main() { return; } - // Construit la liste des lundis (1 par semaine) - const mondays: Date[] = []; - const mondayThisWeek = mondayOfThisWeekUTC(); - if (INCLUDE_CURRENT) mondays.push(mondayThisWeek); + // Construit la liste des dimanches (1 par semaine) + const sundays: Date[] = []; + const sundayThisWeek = sundayOfThisWeekUTC(); + if (INCLUDE_CURRENT) sundays.push(sundayThisWeek); for (let n = 1; n <= PREVIOUS_WEEKS; n++) { - mondays.push(mondayNWeeksBefore(mondayThisWeek, n)); + sundays.push(sundayNWeeksBefore(sundayThisWeek, n)); } // Prépare les lignes (1 timesheet / employé / semaine) const rows: Prisma.TimesheetsCreateManyInput[] = []; for (const e of employees) { - for (const monday of mondays) { + for (const sunday of sundays) { rows.push({ employee_id: e.id, - start_date: monday, + start_date: sunday, is_approved: Math.random() < 0.3, } as Prisma.TimesheetsCreateManyInput); } diff --git a/prisma/mock-seeds-scripts/10-shifts.ts b/prisma/mock-seeds-scripts/10-shifts.ts index 878bc43..9d752b0 100644 --- a/prisma/mock-seeds-scripts/10-shifts.ts +++ b/prisma/mock-seeds-scripts/10-shifts.ts @@ -71,7 +71,7 @@ async function getOrCreateTimesheet(employee_id: number, start_date: Date) { async function main() { // --- Bank codes (pondérés: surtout G1 = régulier) --- - const BANKS = ['G1', 'G56', 'G48', 'G700', 'G105', 'G305'] as const; + const BANKS = ['G1', 'G56', 'G48','G105','G104', 'G305'] as const; const WEIGHTED_CODES = [ 'G1','G1','G1','G1','G1','G1','G1','G1','G1','G1','G1','G1', 'G56','G48','G104','G105','G305','G1','G1','G1','G1','G1','G1' @@ -181,7 +181,7 @@ async function main() { data: { timesheet_id: ts.id, bank_code_id: bcMorningId, - comment: `Matin J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} — ${bcMorningCode}`, + comment: `Matin J${di + 1} (sem ${monday.toISOString().slice(0, 10)}) emp ${e.id} - ${bcMorningCode}`, date, start_time: timeAt(startH, startM), end_time: timeAt(lunchStartHM.h, lunchStartHM.m),