diff --git a/apps/api/src/account/account.service.ts b/apps/api/src/account/account.service.ts index f4d5181..39ec7b5 100644 --- a/apps/api/src/account/account.service.ts +++ b/apps/api/src/account/account.service.ts @@ -18,6 +18,13 @@ export class AccountService { ) {} public async create(createAccountDto: CreateAccountDto): Promise { + const isExist = await this.accountModel.exists({ username: createAccountDto.username }).exec(); + + if (isExist) + throw new BadRequestException( + `Account with username '${createAccountDto.username}' already exists` + ); + Object.keys(createAccountDto).forEach((field) => { if (['_id', '__v'].includes(field)) throw new BadRequestException(`Prop ${field} is not allowed`);