Skip to content

Commit df2575b

Browse files
authored
Merge pull request #252 from boostcampwm-2024/feat/#251-add-management-guest
게스트 삭제 기능
2 parents 631ede5 + c01169c commit df2575b

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

back/src/domains/user/controller/user.controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Body,
33
Controller,
4+
Delete,
45
Get,
56
HttpCode,
67
HttpStatus,
@@ -98,6 +99,12 @@ export class UserController {
9899
return userInfo;
99100
}
100101

102+
@UseGuards(SessionAuthGuard(USER_STATUS.ADMIN))
103+
@Delete('/guest')
104+
async deleteGuestMode() {
105+
return await this.userService.removeAllGuest();
106+
}
107+
101108
@ApiOperation({ summary: '로그인', description: 'id, password를 받아 로그인 요청을 처리한다.' })
102109
@ApiBody({
103110
type: UserLoginDto,

back/src/domains/user/repository/user.repository.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ export class UserRepository {
3131
return this.userRepository.findOne({ where: { loginId } });
3232
}
3333

34-
findOneOrFail({ where }) {
35-
if (where) {
36-
return where.id;
37-
} else {
38-
return 'no';
39-
}
34+
async deleteAllGuest() {
35+
return this.userRepository.delete({
36+
checkGuest: true,
37+
});
4038
}
4139
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Logger,
88
UnauthorizedException,
99
} from '@nestjs/common';
10+
import { Cron } from '@nestjs/schedule';
1011
import * as bcrypt from 'bcryptjs';
1112
import Redis from 'ioredis';
1213
import { DataSource } from 'typeorm';
@@ -179,4 +180,18 @@ export class UserService {
179180
throw new InternalServerErrorException('게스트 사용자 생성에 실패하였습니다.');
180181
}
181182
}
183+
184+
@Cron('0 0 0 * * *', { name: 'removeGuestReservation' })
185+
async removeAllGuest() {
186+
try {
187+
const queryRunner = this.dataSource.createQueryRunner();
188+
await queryRunner.connect();
189+
await queryRunner.startTransaction();
190+
191+
return this.userRepository.deleteAllGuest();
192+
} catch (err) {
193+
this.logger.error(err.name, err.stack);
194+
throw new InternalServerErrorException('게스트 사용자 삭제에 실패하였습니다.');
195+
}
196+
}
182197
}

0 commit comments

Comments
 (0)