feat: update create junior payload and add new document type

This commit is contained in:
Abdalhamid Alhamad
2025-05-14 14:53:22 +03:00
parent cbade0a87d
commit 35ab3df7c1
5 changed files with 24 additions and 8 deletions

View File

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