Modifying cleanUpExpiredReservations code to actually delete expired stuff
This commit is contained in:
parent
e3402fed65
commit
7307cad350
2 changed files with 14 additions and 1 deletions
|
|
@ -97,7 +97,9 @@ export class ReservationsCronService {
|
||||||
await this.ntfyProvider.sendCronStartNotification(
|
await this.ntfyProvider.sendCronStartNotification(
|
||||||
'cleanUpExpiredReservations',
|
'cleanUpExpiredReservations',
|
||||||
)
|
)
|
||||||
const reservations = await this.reservationService.getByDate()
|
const reservations = await this.reservationService.getOlderThanDate(
|
||||||
|
dayjs().subtract(7, 'day'),
|
||||||
|
)
|
||||||
this.loggerService.debug(
|
this.loggerService.debug(
|
||||||
`Found ${reservations.length} reservations to delete`,
|
`Found ${reservations.length} reservations to delete`,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,17 @@ export class ReservationsService {
|
||||||
return await qb.orderBy('dateRangeStart', 'ASC').getMany()
|
return await qb.orderBy('dateRangeStart', 'ASC').getMany()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getOlderThanDate(date = dayjs()) {
|
||||||
|
const query = this.reservationsRepository
|
||||||
|
.createQueryBuilder()
|
||||||
|
.where(`(DATE(dateRangeStart) < DATE(:startDate)`, {
|
||||||
|
startDate: date.toISOString(),
|
||||||
|
})
|
||||||
|
.orderBy('dateRangeStart', 'ASC')
|
||||||
|
|
||||||
|
return await query.getMany()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all reservations that have not been scheduled that are within the reservation window
|
* Gets all reservations that have not been scheduled that are within the reservation window
|
||||||
* @returns Reservations that can be scheduled
|
* @returns Reservations that can be scheduled
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue