2023-05-26 15:43:14 -05:00
|
|
|
import { Inject } from '@nestjs/common'
|
|
|
|
|
import { Process, Processor } from '@nestjs/bull'
|
|
|
|
|
import { Job } from 'bull'
|
|
|
|
|
import { instanceToPlain, plainToInstance } from 'class-transformer'
|
|
|
|
|
import { RESERVATIONS_QUEUE_NAME } from './config'
|
|
|
|
|
import { Reservation } from './entity'
|
|
|
|
|
import { BaanReserverenService } from '../runner/baanreserveren/service'
|
|
|
|
|
import { LoggerService } from '../logger/service'
|
|
|
|
|
|
|
|
|
|
@Processor(RESERVATIONS_QUEUE_NAME)
|
|
|
|
|
export class ReservationsWorker {
|
2023-06-27 16:06:19 +02:00
|
|
|
constructor(
|
|
|
|
|
@Inject(BaanReserverenService)
|
|
|
|
|
private readonly brService: BaanReserverenService,
|
2023-05-26 15:43:14 -05:00
|
|
|
|
2023-06-27 16:06:19 +02:00
|
|
|
@Inject(LoggerService)
|
|
|
|
|
private readonly logger: LoggerService,
|
|
|
|
|
) {}
|
2023-05-26 15:43:14 -05:00
|
|
|
|
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-05-26 15:43:14 -05:00
|
|
|
|
2023-06-27 16:06:19 +02:00
|
|
|
async performReservation(reservation: Reservation) {
|
|
|
|
|
await this.brService.performReservation(reservation)
|
|
|
|
|
}
|
|
|
|
|
}
|