Modifying cleanUpExpiredReservations code to actually delete expired stuff
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful

This commit is contained in:
collin 2026-04-28 14:42:50 +02:00
parent e3402fed65
commit 7307cad350
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View file

@ -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`,
) )

View file

@ -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