Changing how getting reservations by date works to not assume 7d in past
This commit is contained in:
parent
d34cfcdfeb
commit
7002b44936
2 changed files with 7 additions and 3 deletions
|
|
@ -3,6 +3,7 @@ import { Inject, Injectable } from '@nestjs/common'
|
||||||
import { Cron, CronExpression } from '@nestjs/schedule'
|
import { Cron, CronExpression } from '@nestjs/schedule'
|
||||||
import { Queue } from 'bull'
|
import { Queue } from 'bull'
|
||||||
|
|
||||||
|
import dayjs from '../common/dayjs'
|
||||||
import { LoggerService } from '../logger/service'
|
import { LoggerService } from '../logger/service'
|
||||||
import { RESERVATIONS_QUEUE_NAME } from './config'
|
import { RESERVATIONS_QUEUE_NAME } from './config'
|
||||||
import { ReservationsService } from './service'
|
import { ReservationsService } from './service'
|
||||||
|
|
@ -25,7 +26,9 @@ export class ReservationsCronService {
|
||||||
timeZone: 'Europe/Amsterdam',
|
timeZone: 'Europe/Amsterdam',
|
||||||
})
|
})
|
||||||
async handleDailyReservations() {
|
async handleDailyReservations() {
|
||||||
const reservationsToPerform = await this.reservationService.getByDate()
|
const reservationsToPerform = await this.reservationService.getByDate(
|
||||||
|
dayjs().subtract(7, 'days'),
|
||||||
|
)
|
||||||
this.loggerService.log(
|
this.loggerService.log(
|
||||||
`Found ${reservationsToPerform.length} reservations to perform`,
|
`Found ${reservationsToPerform.length} reservations to perform`,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,15 @@ export class ReservationsService {
|
||||||
async getByDate(date = dayjs()) {
|
async getByDate(date = dayjs()) {
|
||||||
return await this.reservationsRepository
|
return await this.reservationsRepository
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.where(`DATE(dateRangeStart, '-7 day') = DATE(:date)`, { date })
|
.where(`DATE(dateRangeStart) = DATE(:date)`, { date })
|
||||||
.getMany()
|
.getMany()
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByDateOnWaitingList(date = dayjs()) {
|
async getByDateOnWaitingList(date = dayjs()) {
|
||||||
return await this.reservationsRepository
|
return await this.reservationsRepository
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.where(`DATE(dateRangeStart, '-7 day') = DATE(:date)`, { date })
|
.where(`DATE(dateRangeStart) <= DATE(:date)`, { date })
|
||||||
|
.andWhere(`DATE(dateRangeEnd) >= DATE(:date)`, { date })
|
||||||
.andWhere('waitListed = true')
|
.andWhere('waitListed = true')
|
||||||
.getMany()
|
.getMany()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue