Debugging some issues with schedulable reservations

This commit is contained in:
Collin Duncan 2023-09-13 12:01:06 +02:00
parent 9dc55e09cf
commit 8dd435a950
No known key found for this signature in database
3 changed files with 12 additions and 6 deletions

View file

@ -41,7 +41,7 @@ export class ReservationsController {
@Query('schedulable') schedulable?: boolean,
) {
if (schedulable) {
return this.reservationsService.getScheduleable()
return this.reservationsService.getSchedulable()
}
if (date) {
return this.reservationsService.getByDate(date)

View file

@ -26,8 +26,7 @@ export class ReservationsCronService {
})
async handleDailyReservations() {
this.loggerService.log('handleDailyReservations beginning')
const reservationsToPerform =
await this.reservationService.getScheduleable()
const reservationsToPerform = await this.reservationService.getSchedulable()
this.loggerService.log(
`Found ${reservationsToPerform.length} reservations to perform`,
)

View file

@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import dayjs from '../common/dayjs'
import { LoggerService } from '../logger/service.logger'
import { BaanReserverenService } from '../runner/baanreserveren/service'
import { Reservation } from './entity'
@ -14,6 +15,9 @@ export class ReservationsService {
@Inject(BaanReserverenService)
private readonly brService: BaanReserverenService,
@Inject(LoggerService)
private readonly loggerService: LoggerService,
) {}
async getAll() {
@ -35,14 +39,17 @@ export class ReservationsService {
* 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
async getSchedulable() {
const query = this.reservationsRepository
.createQueryBuilder()
.where(`DATE(dateRangeStart) <= DATE(:date)`, {
date: dayjs().add(7, 'days'),
})
.andWhere(`waitListed = false`)
.getMany()
this.loggerService.debug('Query: ' + query.getSql())
return await query.getMany()
}
async getByDateOnWaitingList(date = dayjs()) {