import { PrismaClient, Prisma, LeaveTypes, LeaveApprovalStatus } from '@prisma/client'; const prisma = new PrismaClient(); function dateOn(y: number, m: number, d: number) { // stocke une date (pour @db.Date) à minuit UTC return new Date(Date.UTC(y, m - 1, d, 0, 0, 0)); } async function main() { const year = new Date().getFullYear(); const today = new Date(); const employees = await prisma.employees.findMany({ select: { id: true } }); const bankCodes = await prisma.bankCodes.findMany({ where: { type: 'LEAVE' }, select: { id: true }, }); if (!employees.length || !bankCodes.length) { console.warn('No employees or LEAVE bank codes; aborting'); return; } const types: LeaveTypes[] = [ LeaveTypes.SICK, LeaveTypes.VACATION, LeaveTypes.UNPAID, LeaveTypes.BEREAVEMENT, LeaveTypes.PARENTAL, LeaveTypes.LEGAL, LeaveTypes.WEDDING, ]; const statuses: LeaveApprovalStatus[] = [ LeaveApprovalStatus.PENDING, LeaveApprovalStatus.APPROVED, LeaveApprovalStatus.DENIED, LeaveApprovalStatus.CANCELLED, LeaveApprovalStatus.ESCALATED, ]; const futureMonths = [8, 9, 10, 11, 12]; // Août→Déc (1-based) // ✅ typer rows pour éviter never[] const rows: Prisma.LeaveRequestsCreateManyInput[] = []; for (let i = 0; i < 10; i++) { const emp = employees[i % employees.length]; const m = futureMonths[i % futureMonths.length]; const start = dateOn(year, m, 5 + i); // 5..14 if (start <= today) continue; // garantir "futur" const end = Math.random() < 0.5 ? null : dateOn(year, m, 6 + i); const type = types[i % types.length]; const status = statuses[i % statuses.length]; const bc = bankCodes[i % bankCodes.length]; rows.push({ employee_id: emp.id, bank_code_id: bc.id, leave_type: type, start_date_time: start, end_date_time: end, // ok: Date | null comment: `Future leave #${i + 1}`, approval_status: status, }); } if (rows.length) { await prisma.leaveRequests.createMany({ data: rows }); } console.log(`✓ LeaveRequests (future): ${rows.length} rows`); } main().finally(() => prisma.$disconnect());