Skip to content

Commit bdc02fc

Browse files
committed
Merge branch 'refs/heads/dev'
2 parents 21ac04b + ee60100 commit bdc02fc

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RedisService } from '@liaoliaots/nestjs-redis';
2-
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
2+
import { Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common';
33
import { Cron, SchedulerRegistry } from '@nestjs/schedule';
44
import { CronJob } from 'cron';
55
import Redis from 'ioredis';
@@ -20,6 +20,7 @@ import { WaitingQueueService } from './waiting-queue.service';
2020
@Injectable()
2121
export class OpenBookingService implements OnApplicationBootstrap {
2222
private readonly redis: Redis | null;
23+
private readonly logger = new Logger(OpenBookingService.name);
2324

2425
constructor(
2526
private redisService: RedisService,
@@ -48,9 +49,13 @@ export class OpenBookingService implements OnApplicationBootstrap {
4849

4950
@Cron(ONE_MINUTE_BEFORE_THE_HOUR)
5051
async scheduleUpcomingReservations() {
51-
const comingEvents = await this.eventRepository.selectUpcomingEvents();
52-
await this.scheduleUpcomingReservationsToOpen(comingEvents);
53-
await this.scheduleUpcomingReservationsToClose(comingEvents);
52+
try {
53+
const comingEvents = await this.eventRepository.selectUpcomingEvents();
54+
await this.scheduleUpcomingReservationsToOpen(comingEvents);
55+
await this.scheduleUpcomingReservationsToClose(comingEvents);
56+
} catch (error) {
57+
this.logger.error(error);
58+
}
5459
}
5560

5661
private async scheduleUpcomingReservationsToOpen(comingEvents: Event[]) {

back/src/domains/user/service/user.service.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import {
1010
import { Cron } from '@nestjs/schedule';
1111
import * as bcrypt from 'bcryptjs';
1212
import Redis from 'ioredis';
13-
import { DataSource } from 'typeorm';
13+
import { DataSource, In } from 'typeorm';
1414
import { v4 as uuidv4 } from 'uuid';
1515

1616
import { USER_STATUS } from '../../../auth/const/userStatus.const';
1717
import { AuthService } from '../../../auth/service/auth.service';
1818
import { UserParamDto } from '../../../util/user-injection/userParamDto';
19+
import { Reservation } from '../../reservation/entity/reservation.entity';
20+
import { ReservedSeat } from '../../reservation/entity/reservedSeat.entity';
1921
import { USER_ROLE } from '../const/userRole';
2022
import { UserCreateDto } from '../dto/userCreate.dto';
2123
import { UserInfoDto } from '../dto/userInfo.dto';
@@ -183,14 +185,24 @@ export class UserService {
183185

184186
@Cron('0 0 0 * * *', { name: 'removeGuestReservation' })
185187
async removeAllGuest() {
188+
const queryRunner = this.dataSource.createQueryRunner();
189+
await queryRunner.connect();
190+
await queryRunner.startTransaction();
186191
try {
187-
const queryRunner = this.dataSource.createQueryRunner();
188-
await queryRunner.connect();
189-
await queryRunner.startTransaction();
192+
const user = await queryRunner.manager.find(User, { where: { checkGuest: true } });
193+
const userIds = user.map((u) => u.id);
194+
195+
const reservationIds = await queryRunner.manager.find(Reservation, { where: { user: In(userIds) } });
196+
await queryRunner.manager.delete(ReservedSeat, { reservation: In(reservationIds.map((r) => r.id)) });
197+
await queryRunner.manager.delete(Reservation, { user: In(userIds) });
198+
await queryRunner.manager.delete(User, { id: In(userIds) });
199+
200+
await queryRunner.commitTransaction();
190201

191202
return this.userRepository.deleteAllGuest();
192203
} catch (err) {
193204
this.logger.error(err.name, err.stack);
205+
await queryRunner.rollbackTransaction();
194206
throw new InternalServerErrorException('게스트 사용자 삭제에 실패하였습니다.');
195207
}
196208
}

0 commit comments

Comments
 (0)