Changing how cron fetches available reservations to schedule
This commit is contained in:
parent
931a8b7f6c
commit
1da322ed05
2 changed files with 16 additions and 4 deletions
|
|
@ -3,7 +3,6 @@ import { Inject, Injectable } from '@nestjs/common'
|
|||
import { Cron, CronExpression } from '@nestjs/schedule'
|
||||
import { Queue } from 'bull'
|
||||
|
||||
import dayjs from '../common/dayjs'
|
||||
import { LoggerService } from '../logger/service.logger'
|
||||
import { RESERVATIONS_QUEUE_NAME } from './config'
|
||||
import { ReservationsService } from './service'
|
||||
|
|
@ -27,9 +26,8 @@ export class ReservationsCronService {
|
|||
})
|
||||
async handleDailyReservations() {
|
||||
this.loggerService.log('handleDailyReservations beginning')
|
||||
const reservationsToPerform = await this.reservationService.getByDate(
|
||||
dayjs().subtract(7, 'days'),
|
||||
)
|
||||
const reservationsToPerform =
|
||||
await this.reservationService.getScheduleable()
|
||||
this.loggerService.log(
|
||||
`Found ${reservationsToPerform.length} reservations to perform`,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,20 @@ export class ReservationsService {
|
|||
.getMany()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all reservations that have not been scheduled that are within the reservation window
|
||||
* @returns Reservations that can be scheduled
|
||||
*/
|
||||
async getScheduleable() {
|
||||
return await this.reservationsRepository
|
||||
.createQueryBuilder()
|
||||
.where(`DATE(dateRangeStart) <= DATE(:date)`, {
|
||||
date: dayjs().add(7, 'days'),
|
||||
})
|
||||
.andWhere(`waitListed = false`)
|
||||
.getMany()
|
||||
}
|
||||
|
||||
async getByDateOnWaitingList(date = dayjs()) {
|
||||
return await this.reservationsRepository
|
||||
.createQueryBuilder()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue