Skip to content

Commit 58938e2

Browse files
authored
Merge pull request #253 from boostcampwm-2024/feat/#233-admin-init-opened-event
관리자 기능: 오픈된 이벤트 상태 초기화
2 parents df2575b + be0bb56 commit 58938e2

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

back/src/domains/booking/controller/booking.controller.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,16 @@ export class BookingController {
195195
async reloadOpenTarget() {
196196
await this.openBookingService.scheduleUpcomingReservations();
197197
}
198+
199+
@Post('init/:eventId')
200+
@UseGuards(SessionAuthGuard(USER_STATUS.ADMIN))
201+
@ApiOperation({
202+
summary: 'ADMIN: 예약 초기화',
203+
description: '특정 이벤트의 예약 상태를 초기화한다.',
204+
})
205+
@ApiOkResponse({ description: '예약 초기화 완료' })
206+
@ApiUnauthorizedResponse({ description: '인증 실패' })
207+
async initReservation(@Param('eventId') eventId: number) {
208+
await this.openBookingService.initReservation(eventId);
209+
}
198210
}

back/src/domains/booking/service/in-booking.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Redis from 'ioredis';
55

66
import { AuthService } from '../../../auth/service/auth.service';
77
import { UserService } from '../../user/service/user.service';
8+
import { IN_BOOKING_DEFAULT_MAX_SIZE } from '../const/inBookingDefaultMaxSize.const';
89

910
type InBookingSession = {
1011
sid: string;
@@ -26,7 +27,11 @@ export class InBookingService {
2627
}
2728

2829
async getInBookingSessionsDefaultMaxSize() {
29-
return parseInt(await this.redis.get('in-booking:default-max-size'));
30+
const defaultMaxSizeData = await this.redis.get('in-booking:default-max-size');
31+
if (defaultMaxSizeData) {
32+
return parseInt(defaultMaxSizeData);
33+
}
34+
return IN_BOOKING_DEFAULT_MAX_SIZE;
3035
}
3136

3237
async setInBookingSessionsDefaultMaxSize(size: number) {

back/src/domains/booking/service/open-booking.service.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)