mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-29 15:49:44 +00:00
feat: update create junior payload and add new document type
This commit is contained in:
@ -37,7 +37,7 @@ export class CustomerRepository {
|
||||
profession: body.profession,
|
||||
professionType: body.professionType,
|
||||
isPep: body.isPep,
|
||||
|
||||
profilePictureId: body.profilePictureId,
|
||||
civilIdFrontId: body.civilIdFrontId,
|
||||
civilIdBackId: body.civilIdBackId,
|
||||
}),
|
||||
|
@ -2,10 +2,10 @@ import { DocumentType } from '../enums';
|
||||
|
||||
export const BUCKETS: Record<DocumentType, string> = {
|
||||
[DocumentType.PROFILE_PICTURE]: 'profile-pictures',
|
||||
[DocumentType.PASSPORT]: 'passports',
|
||||
[DocumentType.DEFAULT_AVATAR]: 'avatars',
|
||||
[DocumentType.DEFAULT_TASKS_LOGO]: 'tasks-logo',
|
||||
[DocumentType.CUSTOM_AVATAR]: 'avatars',
|
||||
[DocumentType.CUSTOM_TASKS_LOGO]: 'tasks-logo',
|
||||
[DocumentType.GOALS]: 'goals',
|
||||
[DocumentType.IDENTIFICATION_CARD]: 'identification-cards',
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
export enum DocumentType {
|
||||
PROFILE_PICTURE = 'PROFILE_PICTURE',
|
||||
PASSPORT = 'PASSPORT',
|
||||
IDENTIFICATION_CARD = 'IDENTIFICATION_CARD',
|
||||
DEFAULT_AVATAR = 'DEFAULT_AVATAR',
|
||||
DEFAULT_TASKS_LOGO = 'DEFAULT_TASKS_LOGO',
|
||||
CUSTOM_AVATAR = 'CUSTOM_AVATAR',
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsDateString, IsEmail, IsEnum, IsNotEmpty, IsString, IsUUID, Matches } from 'class-validator';
|
||||
import { IsDateString, IsEmail, IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID, Matches } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { COUNTRY_CODE_REGEX } from '~/auth/constants';
|
||||
import { IsValidPhoneNumber } from '~/core/decorators/validations';
|
||||
@ -10,12 +10,14 @@ export class CreateJuniorRequestDto {
|
||||
@Matches(COUNTRY_CODE_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.countryCode' }),
|
||||
})
|
||||
@IsOptional()
|
||||
countryCode: string = '+966';
|
||||
|
||||
@ApiProperty({ example: '787259134' })
|
||||
@IsValidPhoneNumber({
|
||||
message: i18n('validation.IsValidPhoneNumber', { path: 'general', property: 'auth.phoneNumber' }),
|
||||
})
|
||||
@IsOptional()
|
||||
phoneNumber!: string;
|
||||
|
||||
@ApiProperty({ example: 'John' })
|
||||
@ -51,4 +53,9 @@ export class CreateJuniorRequestDto {
|
||||
@ApiProperty({ example: 'bf342-3f3f-3f3f-3f3f' })
|
||||
@IsUUID('4', { message: i18n('validation.IsUUID', { path: 'general', property: 'junior.civilIdBackId' }) })
|
||||
civilIdBackId!: string;
|
||||
|
||||
@ApiProperty({ example: '123e4567-e89b-12d3-a456-426614174000' })
|
||||
@IsUUID('4', { message: i18n('validation.IsUUID', { path: 'general', property: 'customer.profilePictureId' }) })
|
||||
@IsOptional()
|
||||
profilePictureId!: string;
|
||||
}
|
||||
|
@ -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