Skip to content

Commit 06b2e33

Browse files
committed
✨ feat: 예매 내역 삭제 시 좌석 반납
Issue Resolved: #254
1 parent 58938e2 commit 06b2e33

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

back/src/domains/booking/booking.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ import { WaitingQueueService } from './service/waiting-queue.service';
2525
WaitingQueueService,
2626
EnterBookingService,
2727
],
28-
exports: [InBookingService],
28+
exports: [BookingService, InBookingService],
2929
})
3030
export class BookingModule {}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ export class BookingService {
155155
}
156156
}
157157

158+
async freeSeatsIfEventOpened(eventId: number, seats: [number, number][]) {
159+
if (await this.openBookingService.isEventOpened(eventId)) {
160+
await Promise.all(seats.map((seat) => this.bookingSeatsService.updateSeatDeleted(eventId, seat)));
161+
}
162+
}
163+
158164
async getTimeMs(): Promise<ServerTimeDto> {
159165
try {
160166
return {

back/src/domains/reservation/repository/reservation.repository.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ export class ReservationRepository {
1818
});
1919
}
2020

21+
async findReservationByIdMatchedUserId(userId: number, reservationId: number) {
22+
return await this.ReservationRepository.findOne({
23+
where: {
24+
id: reservationId,
25+
user: { id: userId },
26+
},
27+
});
28+
}
29+
2130
async deleteReservationByIdMatchedUserId(userId: number, reservationId: number) {
2231
return await this.ReservationRepository.softDelete({
2332
id: reservationId,

back/src/domains/reservation/service/reservation.service.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DataSource, In, QueryRunner } from 'typeorm';
66
import { UserParamDto } from 'src/util/user-injection/userParamDto';
77

88
import { AuthService } from '../../../auth/service/auth.service';
9+
import { BookingService } from '../../booking/service/booking.service';
910
import { InBookingService } from '../../booking/service/in-booking.service';
1011
import { Event } from '../../event/entity/event.entity';
1112
import { Place } from '../../place/entity/place.entity';
@@ -32,6 +33,7 @@ export class ReservationService {
3233
@Inject() private readonly redisService: RedisService,
3334
@Inject() private readonly dataSource: DataSource,
3435
@Inject() private readonly authService: AuthService,
36+
@Inject() private readonly bookingService: BookingService,
3537
@Inject() private readonly inBookingService: InBookingService,
3638
@Inject() private readonly userService: UserService,
3739
) {
@@ -76,9 +78,17 @@ export class ReservationService {
7678
}
7779

7880
async deleteReservation({ id }: UserParamDto, { reservationId }: ReservationIdDto) {
79-
const result = await this.reservationRepository.deleteReservationByIdMatchedUserId(id, reservationId);
80-
if (!result.affected)
81+
const reservation = await this.reservationRepository.findReservationByIdMatchedUserId(id, reservationId);
82+
if (!reservation) {
8183
throw new BadRequestException(`사용자의 해당 예매 내역[${reservationId}]가 존재하지 않습니다.`);
84+
}
85+
86+
const eventId = (await reservation.event).id;
87+
const reservedSeats = await reservation.reservedSeats;
88+
const reservedSeatsData: [number, number][] = reservedSeats.map((seat) => [seat.row - 1, seat.col - 1]);
89+
await this.bookingService.freeSeatsIfEventOpened(eventId, reservedSeatsData);
90+
91+
await this.reservationRepository.deleteReservationByIdMatchedUserId(id, reservationId);
8292
}
8393

8494
validateReservationLength(seats: ReservationSeatInfoDto[]) {

0 commit comments

Comments
 (0)