autobaan/src/reservations/worker.ts

36 lines
1 KiB
TypeScript
Raw Normal View History

import { Process, Processor } from '@nestjs/bull'
import { Inject } from '@nestjs/common'
import { Job } from 'bull'
import { instanceToPlain, plainToInstance } from 'class-transformer'
import { LoggerService } from '../logger/service'
import { BaanReserverenService } from '../runner/baanreserveren/service'
import { RESERVATIONS_QUEUE_NAME } from './config'
import { Reservation } from './entity'
@Processor(RESERVATIONS_QUEUE_NAME)
export class ReservationsWorker {
2023-06-27 16:06:19 +02:00
constructor(
@Inject(BaanReserverenService)
private readonly brService: BaanReserverenService,
2023-06-27 16:06:19 +02:00
@Inject(LoggerService)
private readonly logger: LoggerService,
) {}
2023-06-27 16:06:19 +02:00
@Process()
async handleReservationJob(job: Job<Reservation>) {
const reservation = plainToInstance(Reservation, job.data, {
groups: ['password'],
})
this.logger.log('Handling reservation', {
reservation: instanceToPlain(reservation),
})
await this.performReservation(reservation)
}
2023-06-27 16:06:19 +02:00
async performReservation(reservation: Reservation) {
await this.brService.performReservation(reservation)
}
}