All files / src/domains/hr/leave/jobs leave-accrual.processor.ts

0% Statements 0/17
0% Branches 0/12
0% Functions 0/2
0% Lines 0/15

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                                                                             
import { Processor, WorkerHost } from '@nestjs/bullmq';
import { Job } from 'bullmq';
import { Logger } from '@nestjs/common';
import { LeaveAccrualEngine } from '../accrual/leave-accrual.engine';
 
@Processor('leave-accrual-processing')
export class LeaveAccrualProcessor extends WorkerHost {
  private readonly logger = new Logger(LeaveAccrualProcessor.name);
 
  constructor(private accrualEngine: LeaveAccrualEngine) {
    super();
  }
 
  async process(job: Job<any, any, string>): Promise<any> {
    const { tenantId, scheduleId, executionDate, isDryRun, userId } = job.data;
    this.logger.log(
      `Starting leave accrual processing for tenant ${tenantId}, schedule ${scheduleId}`,
    );
 
    if (job.name === 'leave.accrual.process') {
      return this.accrualEngine.executeAccrual(
        tenantId,
        scheduleId,
        executionDate,
        isDryRun || false,
        userId || 'system',
      );
    }
 
    if (job.name === 'leave.accrual.reconcile') {
      this.logger.log(`Reconciling accrual for tenant ${tenantId}`);
      // Stub implementation
      return { status: 'reconciled' };
    }
 
    return { status: 'ignored' };
  }
}