Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/user/dto/response/withdrawal-user-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';

export class WithdrawalUserResponse {
@ApiProperty({ description: '회원 탈퇴 여부', example: true })
isUserWithdraw: boolean;
}
13 changes: 13 additions & 0 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,17 @@ export class UserController {
GlobalResponseCode.OK,
);
}

@Post('withdrawal')
@UseGuards(JwtAuthGuard)
@ApiOperation({
summary: '회원 탈퇴',
description: '현재 회원을 탈퇴시킵니다.',
})
@ApiOkResponse({ type: FindingPasswordResponse, description: '임시 비밀번호 전송 완료' })
@ApiBearerAuth()
async withdrawalUser(@ExtractPayload() userId: number) {
const userStatus = await this.userService.withdrawalUser(userId);
return BaseResponse.of(UserConverter.toWithdrawalUserResponse(userStatus));
}
}
7 changes: 7 additions & 0 deletions src/user/user.converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Password } from './entity/password';
import { UserReport } from './entity/user-report.entity';
import { User } from './entity/user.entity';
import { UserReportReason } from './enum/user-report-reason';
import { WithdrawalUserResponse } from './dto/response/withdrawal-user-response.dto';

@Injectable()
export class UserConverter implements OnModuleInit {
Expand Down Expand Up @@ -57,4 +58,10 @@ export class UserConverter implements OnModuleInit {
public static toFindingPasswordResponse(isPasswordSended: boolean): FindingPasswordResponse {
return Builder(FindingPasswordResponse).isPasswordSended(isPasswordSended).build();
}

public static toWithdrawalUserResponse(userStatus: User) {
return Builder(WithdrawalUserResponse)
.isUserWithdraw(userStatus.disabledAt ? true : false)
.build();
}
}
8 changes: 8 additions & 0 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ export class UserService {
async sendEmail(request: FindingPasswordRequest, password: string): Promise<void> {
await this.mailService.sendMail(request.email, '[BookJam] 임시 비밀번호 안내', password);
}

async withdrawalUser(userId: number): Promise<User> {
const user: User = await this.userRepository.findOneBy({ userId });
user.disabledAt = new Date();
await this.userRepository.update(userId, user);

return user;
}
}