All files / src/features/queue/processors email.processor.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 3/3
100% Lines 9/9

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                  10x     10x       2x   2x   1x 1x   1x         1x 1x      
import { Processor, WorkerHost } from '@nestjs/bullmq'
import { Job } from 'bullmq'
import { MailService } from '../../mail/mail.service'
import { Logger } from '@nestjs/common'
 
import { SendReceiptJobData } from '../interfaces/email-jobs.interface'
 
@Processor('email')
export class EmailProcessor extends WorkerHost {
    private readonly logger = new Logger(EmailProcessor.name)
 
    constructor(private readonly mailService: MailService) {
        super()
    }
 
    async process(job: Job<SendReceiptJobData, any, string>): Promise<any> {
        this.logger.log(`Processing job ${job.id} of type ${job.name}`)
 
        switch (job.name) {
            case 'send-receipt':
                await this.handleSendReceipt(job.data)
                break
            default:
                this.logger.warn(`Unknown job name: ${job.name}`)
        }
    }
 
    private async handleSendReceipt(data: SendReceiptJobData) {
        await this.mailService.sendReceipt(data.email, data)
        this.logger.log(`Receipt email sent to ${data.email} for event ${data.eventSlug}`)
    }
}