targo-backend/src/time-and-attendance/timesheets/services/timesheet-archive.service.ts

49 lines
1.9 KiB
TypeScript

// import { TimesheetsArchive } from "@prisma/client";
// import { PrismaService } from "src/prisma/prisma.service";
// export class TimesheetArchiveService {
// constructor(private readonly prisma: PrismaService){}
// async archiveOld(): Promise<void> {
// //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<TimesheetsArchive[]> {
// return this.prisma.timesheetsArchive.findMany();
// }
// //fetches an archived timesheet
// async findOneArchived(id: number): Promise<TimesheetsArchive> {
// return this.prisma.timesheetsArchive.findUniqueOrThrow({ where: { id } });
// }
// }