41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
import { Injectable, Logger } from "@nestjs/common";
|
|
import { Cron } from "@nestjs/schedule";
|
|
import { ApiInternalServerErrorResponse, ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
|
import { ExpensesService } from "src/modules/expenses/services/expenses.service";
|
|
import { LeaveRequestsService } from "src/modules/leave-requests/services/leave-request.service";
|
|
import { ShiftsService } from "src/modules/shifts/services/shifts.service";
|
|
import { TimesheetsService } from "src/modules/timesheets/services/timesheets.service";
|
|
|
|
@Injectable()
|
|
export class ArchivalService {
|
|
private readonly logger = new Logger(ArchivalService.name);
|
|
|
|
constructor(
|
|
private readonly timesheetsService: TimesheetsService,
|
|
private readonly expensesService: ExpensesService,
|
|
private readonly shiftsService: ShiftsService,
|
|
private readonly leaveRequestsService: LeaveRequestsService,
|
|
) {}
|
|
|
|
@Cron('0 0 3 * * 1', {timeZone:'America/Toronto'}) // chaque premier lundi du mois à 03h00
|
|
async handleMonthlyArchival() {
|
|
const today = new Date();
|
|
const dayOfMonth = today.getDate();
|
|
|
|
if (dayOfMonth > 7) {
|
|
this.logger.warn('Archive {awaiting 1st monday of the month for archivation process}')
|
|
return;
|
|
}
|
|
|
|
this.logger.log('monthly archivation in process');
|
|
try {
|
|
await this.timesheetsService.archiveOld();
|
|
await this.expensesService.archiveOld();
|
|
await this.shiftsService.archiveOld();
|
|
await this.leaveRequestsService.archiveExpired();
|
|
this.logger.log('archivation process done');
|
|
} catch (err) {
|
|
this.logger.error('an error occured during archivation process ', err);
|
|
}
|
|
}
|
|
} |