mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
feat: finialize creating juniors
This commit is contained in:
@ -1,11 +1,9 @@
|
||||
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
||||
import { FindOptionsWhere } from 'typeorm';
|
||||
import { Transactional } from 'typeorm-transactional';
|
||||
import { Roles } from '~/auth/enums';
|
||||
import { PageOptionsRequestDto } from '~/core/dtos';
|
||||
import { CustomerService } from '~/customer/services';
|
||||
import { DocumentService, OciService } from '~/document/services';
|
||||
import { User } from '~/user/entities';
|
||||
import { UserType } from '~/user/enums';
|
||||
import { UserService } from '~/user/services';
|
||||
import { UserTokenService } from '~/user/services/user-token.service';
|
||||
@ -31,26 +29,18 @@ export class JuniorService {
|
||||
async createJuniors(body: CreateJuniorRequestDto, guardianId: string) {
|
||||
this.logger.log(`Creating junior for guardian ${guardianId}`);
|
||||
|
||||
const searchConditions: FindOptionsWhere<User>[] = [{ email: body.email }];
|
||||
|
||||
if (body.phoneNumber && body.countryCode) {
|
||||
searchConditions.push({
|
||||
phoneNumber: body.phoneNumber,
|
||||
countryCode: body.countryCode,
|
||||
});
|
||||
}
|
||||
|
||||
const existingUser = await this.userService.findUser(searchConditions);
|
||||
const existingUser = await this.userService.findUser({ email: body.email });
|
||||
|
||||
if (existingUser) {
|
||||
this.logger.error(`User with email ${body.email} or phone number ${body.phoneNumber} already exists`);
|
||||
this.logger.error(`User with email ${body.email} already exists`);
|
||||
throw new BadRequestException('USER.ALREADY_EXISTS');
|
||||
}
|
||||
|
||||
const user = await this.userService.createUser({
|
||||
email: body.email,
|
||||
countryCode: body.countryCode,
|
||||
phoneNumber: body.phoneNumber,
|
||||
firstName: body.firstName,
|
||||
lastName: body.lastName,
|
||||
profilePictureId: body.profilePictureId,
|
||||
roles: [Roles.JUNIOR],
|
||||
});
|
||||
|
||||
@ -75,6 +65,7 @@ export class JuniorService {
|
||||
this.logger.error(`Junior ${juniorId} not found`);
|
||||
throw new BadRequestException('JUNIOR.NOT_FOUND');
|
||||
}
|
||||
await this.prepareJuniorImages([junior]);
|
||||
|
||||
this.logger.log(`Junior ${juniorId} found successfully`);
|
||||
return junior;
|
||||
|
||||
Reference in New Issue
Block a user