Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import { Processor, WorkerHost } from '@nestjs/bullmq'; import { Job } from 'bullmq'; import { Logger } from '@nestjs/common'; import { AttendanceCalculationEngine } from '../engine.service'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { Shift, EmployeeShiftAssignment } from '../../schemas'; @Processor('attendance-daily-processing') export class DailyAttendanceProcessor extends WorkerHost { private readonly logger = new Logger(DailyAttendanceProcessor.name); constructor( private engine: AttendanceCalculationEngine, // Inject models needed to find employees ) { super(); } async process(job: Job<any, any, string>): Promise<any> { const { tenantId, date } = job.data; this.logger.log( `Starting daily attendance processing for tenant ${tenantId} on ${date}`, ); // In a real scenario, we would iterate through all active employees // For now, we simulate fetching employee IDs const mockEmployeeIds = ['emp-1', 'emp-2', 'emp-3']; // This would come from EmployeeMaster let processedCount = 0; for (const employeeId of mockEmployeeIds) { try { await this.engine.calculateDailyAttendance(tenantId, employeeId, date); processedCount++; } catch (error) { this.logger.error( `Failed to process attendance for ${employeeId}: ${error.message}`, error.stack, ); } } this.logger.log( `Completed processing ${processedCount} employees for tenant ${tenantId}`, ); return { processedCount }; } } |