apps/api: check if account exists before create

This commit is contained in:
vchikalkin 2024-01-12 16:08:24 +03:00
parent 7ac3f0cc6a
commit 946d977db8

View File

@ -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`);