@@ -6,6 +6,7 @@ import { DataSource, In, QueryRunner } from 'typeorm';
66import { UserParamDto } from 'src/util/user-injection/userParamDto' ;
77
88import { AuthService } from '../../../auth/service/auth.service' ;
9+ import { BookingService } from '../../booking/service/booking.service' ;
910import { InBookingService } from '../../booking/service/in-booking.service' ;
1011import { Event } from '../../event/entity/event.entity' ;
1112import { 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