Skip to content

Commit 78c8e82

Browse files
authored
Merge pull request #241 from boostcampwm-2024/feat/#240-seats-flush-when-modify-booking-amount
예매 매수 변경 시 선점한 좌석들 반납
2 parents 9b2134a + 713a495 commit 78c8e82

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,21 @@ export class BookingService {
150150
async setBookingAmount(sid: string, bookingAmount: number) {
151151
const isInBooking = await this.inBookingService.isInBooking(sid);
152152
if (isInBooking) {
153+
await this.flushBookedSeats(sid);
153154
return await this.inBookingService.setBookingAmount(sid, bookingAmount);
154155
}
155156
return await this.enterBookingService.setBookingAmount(sid, bookingAmount);
156157
}
157158

159+
private async flushBookedSeats(sid: string) {
160+
const bookedSeats = await this.inBookingService.getBookedSeats(sid);
161+
if (bookedSeats.length > 0) {
162+
const eventId = await this.userService.getUserEventTarget(sid);
163+
await Promise.all(bookedSeats.map((seat) => this.bookingSeatsService.updateSeatDeleted(eventId, seat)));
164+
await this.inBookingService.removeBookedSeats(sid);
165+
}
166+
}
167+
158168
async getTimeMs(): Promise<ServerTimeDto> {
159169
try {
160170
return {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ export class InBookingService {
104104
await this.setSession(eventId, session);
105105
}
106106

107+
async removeBookedSeats(sid: string) {
108+
const eventId = await this.getTargetEventId(sid);
109+
const session = await this.getSession(eventId, sid);
110+
session.bookedSeats = [];
111+
await this.setSession(eventId, session);
112+
}
113+
107114
async getIsSaved(sid: string) {
108115
const eventId = await this.getTargetEventId(sid);
109116
const session = await this.getSession(eventId, sid);

0 commit comments

Comments
 (0)