Skip to content

Commit 7228286

Browse files
committed
2 parents e1d80d0 + 3be5783 commit 7228286

File tree

7 files changed

+66
-18
lines changed

7 files changed

+66
-18
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/program/service/program.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
22

3+
import { Event } from 'src/domains/event/entity/event.entity';
4+
35
import { PlaceMainPageDto } from '../dto/placeMainPage.dto';
46
import { ProgramCreationDto } from '../dto/programCreation.dto';
57
import { ProgramIdDto } from '../dto/programId.dto';
@@ -39,9 +41,12 @@ export class ProgramService {
3941
}
4042

4143
private async convertProgramToSpecificDto(program: Program): Promise<ProgramSpecificDto> {
44+
const now = new Date();
4245
const [place, events] = await Promise.all([program.place, program.events]);
43-
44-
return new ProgramSpecificDto({ ...program, place, events });
46+
const openedEvents: Event[] = events.filter((event) => {
47+
return event.reservationCloseDate >= now;
48+
});
49+
return new ProgramSpecificDto({ ...program, place, events: openedEvents });
4550
}
4651

4752
async create(programCreationDto: ProgramCreationDto): Promise<void> {

back/src/domains/reservation/entity/reservedSeat.entity.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, Unique } from 'typeorm';
1+
import {
2+
Column,
3+
DeleteDateColumn,
4+
Entity,
5+
JoinColumn,
6+
ManyToOne,
7+
PrimaryGeneratedColumn,
8+
Unique,
9+
} from 'typeorm';
210

311
import { Event } from '../../event/entity/event.entity';
412

513
import { Reservation } from './reservation.entity';
614

715
@Entity({ name: 'Reserved_Seat' })
8-
@Unique(['row', 'col', 'sectionName', 'event'])
16+
@Unique(['row', 'col', 'sectionName', 'event', 'deletedAt'])
917
export class ReservedSeat {
1018
@PrimaryGeneratedColumn('increment')
1119
id: number;
1220

21+
@DeleteDateColumn({ type: 'timestamp', name: 'deleted_at', nullable: true })
22+
deletedAt: Date;
23+
1324
@Column({ type: 'varchar', length: 255, name: 'section_name' })
1425
sectionName: string;
1526

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { Injectable } from '@nestjs/common';
22
import { InjectRepository } from '@nestjs/typeorm';
3-
import { MoreThanOrEqual, Repository } from 'typeorm';
3+
import { DataSource, MoreThanOrEqual, Repository } from 'typeorm';
44

55
import { Reservation } from '../entity/reservation.entity';
66

7+
import { ReservedSeatRepository } from './reservedSeat.repository';
8+
79
@Injectable()
810
export class ReservationRepository {
9-
constructor(@InjectRepository(Reservation) private ReservationRepository: Repository<Reservation>) {}
11+
constructor(
12+
@InjectRepository(Reservation) private ReservationRepository: Repository<Reservation>,
13+
private readonly reservedSeatRepository: ReservedSeatRepository,
14+
private readonly dataSource: DataSource,
15+
) {}
1016

1117
async selectAllReservationAfterNowByUserWithAll(userId: number): Promise<Reservation[]> {
1218
return await this.ReservationRepository.find({
@@ -28,9 +34,12 @@ export class ReservationRepository {
2834
}
2935

3036
async deleteReservationByIdMatchedUserId(userId: number, reservationId: number) {
31-
return await this.ReservationRepository.softDelete({
32-
id: reservationId,
33-
user: { id: userId },
37+
await this.dataSource.transaction(async () => {
38+
await this.reservedSeatRepository.deleteReservedSeatByReservation(reservationId);
39+
await this.ReservationRepository.softDelete({
40+
id: reservationId,
41+
user: { id: userId },
42+
});
3443
});
3544
}
3645

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ export class ReservedSeatRepository {
1212
const reservedSeat = this.reservedSeatRepository.create(reservedSeatData);
1313
return this.reservedSeatRepository.save(reservedSeat);
1414
}
15+
16+
async deleteReservedSeatByReservation(reservationId: number) {
17+
return await this.reservedSeatRepository.softDelete({
18+
reservation: { id: reservationId },
19+
});
20+
}
1521
}

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
}

front/src/components/Navbar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default function Navbar() {
8383
const sliced = data.loginId.slice(0, 12);
8484
if (login) {
8585
login(sliced);
86-
toast.success('geust로 로그인 되었습니다');
86+
toast.success('guest로 로그인 되었습니다');
8787
}
8888
})
8989
.catch(() => {

0 commit comments

Comments
 (0)