@@ -41,6 +41,11 @@ export class OpenBookingService implements OnApplicationBootstrap {
4141 await this . scheduleUpcomingReservations ( ) ;
4242 }
4343
44+ async initReservation ( eventId : number ) {
45+ await this . closeReservationAnyway ( eventId ) ;
46+ await this . openReservationById ( eventId ) ;
47+ }
48+
4449 @Cron ( ONE_MINUTE_BEFORE_THE_HOUR )
4550 async scheduleUpcomingReservations ( ) {
4651 const comingEvents = await this . eventRepository . selectUpcomingEvents ( ) ;
@@ -51,7 +56,9 @@ export class OpenBookingService implements OnApplicationBootstrap {
5156 private async scheduleUpcomingReservationsToOpen ( comingEvents : Event [ ] ) {
5257 const now = new Date ( ) ;
5358 const openedEventIds = new Set ( await this . getOpenedEventIds ( ) ) ;
54- const eventToOpen = comingEvents . filter ( ( event ) => event . reservationOpenDate <= now ) ;
59+ const eventToOpen = comingEvents . filter (
60+ ( event ) => ! openedEventIds . has ( event . id ) && event . reservationOpenDate <= now ,
61+ ) ;
5562 const eventsToScheduleOpen = comingEvents . filter (
5663 ( event ) => ! openedEventIds . has ( event . id ) && event . reservationOpenDate > now ,
5764 ) ;
@@ -154,6 +161,14 @@ export class OpenBookingService implements OnApplicationBootstrap {
154161 await this . redis . set ( `open-booking:${ eventId } :opened` , 'true' ) ;
155162 }
156163
164+ async closeReservationAnyway ( eventId : number ) {
165+ await this . unlinkOpenedEvent ( eventId ) ;
166+ await this . clearWaitingService ( eventId ) ;
167+ await this . clearEnteringService ( eventId ) ;
168+ await this . seatsUpdateService . clearSeatsSubscription ( eventId ) ;
169+ await this . clearInBookingService ( eventId ) ;
170+ }
171+
157172 async closeReservation ( eventId : number ) {
158173 await this . validateClosingEvent ( eventId ) ;
159174 await this . unlinkOpenedEvent ( eventId ) ;
0 commit comments