Adding cron to clean up expired reservations

This commit is contained in:
Collin Duncan 2023-07-29 15:23:13 +02:00
parent 89948e79f4
commit 839c162f1f
No known key found for this signature in database

View file

@ -33,4 +33,18 @@ export class ReservationsCronService {
reservationsToPerform.map((r) => ({ data: r })), reservationsToPerform.map((r) => ({ data: r })),
) )
} }
@Cron(CronExpression.EVERY_DAY_AT_11PM, {
name: 'cleanUpExpiredReservations',
timeZone: 'Europe/Amsterdam',
})
async cleanUpExpiredReservations() {
const reservations = await this.reservationService.getByDate()
this.loggerService.log(
`Found ${reservations.length} reservations to delete`,
)
for (const reservation of reservations) {
await this.reservationService.deleteById(reservation.id)
}
}
} }