import { PrismaClient } from '@prisma/client'; if (process.env.SKIP_LEAVE_REQUESTS === 'true') { console.log("⏭ Seed leave-requests ignoré (SKIP_LEAVE_REQUESTS=true)"); process.exit(0); } const prisma = new PrismaClient(); function timeAt(h:number,m:number) { return new Date(Date.UTC(1970,0,1,h,m,0)); } function daysAgo(n:number) { const d = new Date(); d.setUTCDate(d.getUTCDate() - n); d.setUTCHours(0,0,0,0); return d; } async function main() { const bankCodes = await prisma.bankCodes.findMany({ where: { categorie: 'SHIFT' }, select: { id: true } }); const employees = await prisma.employees.findMany({ select: { id: true } }); for (const e of employees) { const tss = await prisma.timesheets.findMany({ where: { employee_id: e.id }, select: { id: true } }); if (!tss.length) continue; const createdShiftIds: number[] = []; for (let i = 0; i < 8; i++) { const ts = tss[i % tss.length]; const bc = bankCodes[i % bankCodes.length]; const date = daysAgo(200 + i); // bien dans le passé const startH = 7 + (i % 4); // 7..10 const endH = startH + 8; // 15..18 const sh = await prisma.shifts.create({ data: { timesheet_id: ts.id, bank_code_id: bc.id, comment: `Archived-era shift ${i + 1} for emp ${e.id}`, date, start_time: timeAt(startH, 0), end_time: timeAt(endH, 0), is_approved: true, }, }); createdShiftIds.push(sh.id); } for (const sid of createdShiftIds) { const s = await prisma.shifts.findUnique({ where: { id: sid } }); if (!s) continue; await prisma.shiftsArchive.create({ data: { shift_id: s.id, timesheet_id: s.timesheet_id, bank_code_id: s.bank_code_id, comment: s.comment, date: s.date, start_time: s.start_time, end_time: s.end_time, }, }); } } const total = await prisma.shiftsArchive.count(); console.log(`✓ ShiftsArchive: ${total} rows total`); } main().finally(() => prisma.$disconnect());