Skip to content

Commit

Permalink
Merge pull request #224 from boostcampwm-2024/feature/api/defaultUser…
Browse files Browse the repository at this point in the history
…Name

[BE] 회원가입시 기본 닉네임 설정
  • Loading branch information
uuuo3o authored Nov 28, 2024
2 parents d41658b + da57768 commit 5a044e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions BE/src/auth/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class UserRepository extends Repository<User> {
const hashedPassword: string = await bcrypt.hash(password, salt);
const user = this.create({ email, password: hashedPassword });
await queryRunner.manager.save(user);

user.nickname = `익명의 투자자${user.id}`;
await queryRunner.manager.save(user);

const asset = this.assetRepository.create({ user_id: user.id });
await queryRunner.manager.save(asset);

Expand All @@ -52,6 +56,10 @@ export class UserRepository extends Repository<User> {
password: hashedPassword,
});
await this.save(user);

user.nickname = `익명의 투자자${user.id}`;
await queryRunner.manager.save(user);

const asset = this.assetRepository.create({ user_id: user.id });
await queryRunner.manager.save(asset);

Expand Down
4 changes: 4 additions & 0 deletions BE/src/auth/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class UserService {
throw new NotFoundException('존재하지 않는 유저입니다.');
}

if (newName.replaceAll(/ /g, '').includes('익명의투자자')) {
throw new BadRequestException('사용 불가능한 문자가 포함되어 있습니다.');
}

const isDuplicated = await this.userRepository.existsBy({
nickname: newName,
});
Expand Down

0 comments on commit 5a044e4

Please sign in to comment.