apps/api: check if account exists before create
This commit is contained in:
parent
7ac3f0cc6a
commit
946d977db8
@ -18,6 +18,13 @@ export class AccountService {
|
||||
) {}
|
||||
|
||||
public async create(createAccountDto: CreateAccountDto): Promise<Account> {
|
||||
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`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user