// import { TimesheetsArchive } from "@prisma/client"; // import { PrismaService } from "src/prisma/prisma.service"; // export class TimesheetArchiveService { // constructor(private readonly prisma: PrismaService){} // async archiveOld(): Promise { // //calcul du cutoff pour archivation // const cutoff = new Date(); // cutoff.setMonth(cutoff.getMonth() - 6) // await this.prisma.$transaction(async transaction => { // //fetches all timesheets to cutoff // const oldSheets = await transaction.timesheets.findMany({ // where: { shift: { some: { date: { lt: cutoff } } }, // }, // select: { // id: true, // employee_id: true, // is_approved: true, // }, // }); // if( oldSheets.length === 0) return; // //preping data for archivation // const archiveDate = oldSheets.map(sheet => ({ // timesheet_id: sheet.id, // employee_id: sheet.employee_id, // is_approved: sheet.is_approved, // })); // //copying data from timesheets table to archive table // await transaction.timesheetsArchive.createMany({ data: archiveDate }); // //removing data from timesheets table // await transaction.timesheets.deleteMany({ where: { id: { in: oldSheets.map(s => s.id) } } }); // }); // } // //fetches all archived timesheets // async findAllArchived(): Promise { // return this.prisma.timesheetsArchive.findMany(); // } // //fetches an archived timesheet // async findOneArchived(id: number): Promise { // return this.prisma.timesheetsArchive.findUniqueOrThrow({ where: { id } }); // } // }