diff --git a/src/reservations/cron.ts b/src/reservations/cron.ts index 2e9dd96..1cc1a59 100644 --- a/src/reservations/cron.ts +++ b/src/reservations/cron.ts @@ -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`, ) diff --git a/src/reservations/service.ts b/src/reservations/service.ts index bbbf6aa..03d2d4a 100644 --- a/src/reservations/service.ts +++ b/src/reservations/service.ts @@ -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()