mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
feat: update create junior payload and add new document type
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
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';
|
||||
@ -28,10 +30,17 @@ export class JuniorService {
|
||||
@Transactional()
|
||||
async createJuniors(body: CreateJuniorRequestDto, guardianId: string) {
|
||||
this.logger.log(`Creating junior for guardian ${guardianId}`);
|
||||
const existingUser = await this.userService.findUser([
|
||||
{ email: body.email },
|
||||
{ phoneNumber: body.phoneNumber, countryCode: body.countryCode },
|
||||
]);
|
||||
|
||||
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);
|
||||
|
||||
if (existingUser) {
|
||||
this.logger.error(`User with email ${body.email} or phone number ${body.phoneNumber} already exists`);
|
||||
|
||||
Reference in New Issue
Block a user