From 7002b4493603a0734a56da4598c8100cea57a0ce Mon Sep 17 00:00:00 2001 From: Collin Duncan <3679940+cgduncan7@users.noreply.github.com> Date: Sat, 29 Jul 2023 16:30:06 +0200 Subject: [PATCH] Changing how getting reservations by date works to not assume 7d in past --- src/reservations/cron.ts | 5 ++++- src/reservations/service.ts | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/reservations/cron.ts b/src/reservations/cron.ts index 4346327..109b631 100644 --- a/src/reservations/cron.ts +++ b/src/reservations/cron.ts @@ -3,6 +3,7 @@ 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' import { RESERVATIONS_QUEUE_NAME } from './config' import { ReservationsService } from './service' @@ -25,7 +26,9 @@ export class ReservationsCronService { timeZone: 'Europe/Amsterdam', }) async handleDailyReservations() { - const reservationsToPerform = await this.reservationService.getByDate() + const reservationsToPerform = await this.reservationService.getByDate( + dayjs().subtract(7, 'days'), + ) this.loggerService.log( `Found ${reservationsToPerform.length} reservations to perform`, ) diff --git a/src/reservations/service.ts b/src/reservations/service.ts index c27b705..4e7b6f5 100644 --- a/src/reservations/service.ts +++ b/src/reservations/service.ts @@ -23,14 +23,15 @@ export class ReservationsService { async getByDate(date = dayjs()) { return await this.reservationsRepository .createQueryBuilder() - .where(`DATE(dateRangeStart, '-7 day') = DATE(:date)`, { date }) + .where(`DATE(dateRangeStart) = DATE(:date)`, { date }) .getMany() } async getByDateOnWaitingList(date = dayjs()) { return await this.reservationsRepository .createQueryBuilder() - .where(`DATE(dateRangeStart, '-7 day') = DATE(:date)`, { date }) + .where(`DATE(dateRangeStart) <= DATE(:date)`, { date }) + .andWhere(`DATE(dateRangeEnd) >= DATE(:date)`, { date }) .andWhere('waitListed = true') .getMany() }