mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +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,
|
profession: body.profession,
|
||||||
professionType: body.professionType,
|
professionType: body.professionType,
|
||||||
isPep: body.isPep,
|
isPep: body.isPep,
|
||||||
|
profilePictureId: body.profilePictureId,
|
||||||
civilIdFrontId: body.civilIdFrontId,
|
civilIdFrontId: body.civilIdFrontId,
|
||||||
civilIdBackId: body.civilIdBackId,
|
civilIdBackId: body.civilIdBackId,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -2,10 +2,10 @@ import { DocumentType } from '../enums';
|
|||||||
|
|
||||||
export const BUCKETS: Record<DocumentType, string> = {
|
export const BUCKETS: Record<DocumentType, string> = {
|
||||||
[DocumentType.PROFILE_PICTURE]: 'profile-pictures',
|
[DocumentType.PROFILE_PICTURE]: 'profile-pictures',
|
||||||
[DocumentType.PASSPORT]: 'passports',
|
|
||||||
[DocumentType.DEFAULT_AVATAR]: 'avatars',
|
[DocumentType.DEFAULT_AVATAR]: 'avatars',
|
||||||
[DocumentType.DEFAULT_TASKS_LOGO]: 'tasks-logo',
|
[DocumentType.DEFAULT_TASKS_LOGO]: 'tasks-logo',
|
||||||
[DocumentType.CUSTOM_AVATAR]: 'avatars',
|
[DocumentType.CUSTOM_AVATAR]: 'avatars',
|
||||||
[DocumentType.CUSTOM_TASKS_LOGO]: 'tasks-logo',
|
[DocumentType.CUSTOM_TASKS_LOGO]: 'tasks-logo',
|
||||||
[DocumentType.GOALS]: 'goals',
|
[DocumentType.GOALS]: 'goals',
|
||||||
|
[DocumentType.IDENTIFICATION_CARD]: 'identification-cards',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export enum DocumentType {
|
export enum DocumentType {
|
||||||
PROFILE_PICTURE = 'PROFILE_PICTURE',
|
PROFILE_PICTURE = 'PROFILE_PICTURE',
|
||||||
PASSPORT = 'PASSPORT',
|
IDENTIFICATION_CARD = 'IDENTIFICATION_CARD',
|
||||||
DEFAULT_AVATAR = 'DEFAULT_AVATAR',
|
DEFAULT_AVATAR = 'DEFAULT_AVATAR',
|
||||||
DEFAULT_TASKS_LOGO = 'DEFAULT_TASKS_LOGO',
|
DEFAULT_TASKS_LOGO = 'DEFAULT_TASKS_LOGO',
|
||||||
CUSTOM_AVATAR = 'CUSTOM_AVATAR',
|
CUSTOM_AVATAR = 'CUSTOM_AVATAR',
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
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 { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||||
import { COUNTRY_CODE_REGEX } from '~/auth/constants';
|
import { COUNTRY_CODE_REGEX } from '~/auth/constants';
|
||||||
import { IsValidPhoneNumber } from '~/core/decorators/validations';
|
import { IsValidPhoneNumber } from '~/core/decorators/validations';
|
||||||
@ -10,12 +10,14 @@ export class CreateJuniorRequestDto {
|
|||||||
@Matches(COUNTRY_CODE_REGEX, {
|
@Matches(COUNTRY_CODE_REGEX, {
|
||||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.countryCode' }),
|
message: i18n('validation.Matches', { path: 'general', property: 'auth.countryCode' }),
|
||||||
})
|
})
|
||||||
|
@IsOptional()
|
||||||
countryCode: string = '+966';
|
countryCode: string = '+966';
|
||||||
|
|
||||||
@ApiProperty({ example: '787259134' })
|
@ApiProperty({ example: '787259134' })
|
||||||
@IsValidPhoneNumber({
|
@IsValidPhoneNumber({
|
||||||
message: i18n('validation.IsValidPhoneNumber', { path: 'general', property: 'auth.phoneNumber' }),
|
message: i18n('validation.IsValidPhoneNumber', { path: 'general', property: 'auth.phoneNumber' }),
|
||||||
})
|
})
|
||||||
|
@IsOptional()
|
||||||
phoneNumber!: string;
|
phoneNumber!: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'John' })
|
@ApiProperty({ example: 'John' })
|
||||||
@ -51,4 +53,9 @@ export class CreateJuniorRequestDto {
|
|||||||
@ApiProperty({ example: 'bf342-3f3f-3f3f-3f3f' })
|
@ApiProperty({ example: 'bf342-3f3f-3f3f-3f3f' })
|
||||||
@IsUUID('4', { message: i18n('validation.IsUUID', { path: 'general', property: 'junior.civilIdBackId' }) })
|
@IsUUID('4', { message: i18n('validation.IsUUID', { path: 'general', property: 'junior.civilIdBackId' }) })
|
||||||
civilIdBackId!: string;
|
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 { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
||||||
|
import { FindOptionsWhere } from 'typeorm';
|
||||||
import { Transactional } from 'typeorm-transactional';
|
import { Transactional } from 'typeorm-transactional';
|
||||||
import { Roles } from '~/auth/enums';
|
import { Roles } from '~/auth/enums';
|
||||||
import { PageOptionsRequestDto } from '~/core/dtos';
|
import { PageOptionsRequestDto } from '~/core/dtos';
|
||||||
import { CustomerService } from '~/customer/services';
|
import { CustomerService } from '~/customer/services';
|
||||||
import { DocumentService, OciService } from '~/document/services';
|
import { DocumentService, OciService } from '~/document/services';
|
||||||
|
import { User } from '~/user/entities';
|
||||||
import { UserType } from '~/user/enums';
|
import { UserType } from '~/user/enums';
|
||||||
import { UserService } from '~/user/services';
|
import { UserService } from '~/user/services';
|
||||||
import { UserTokenService } from '~/user/services/user-token.service';
|
import { UserTokenService } from '~/user/services/user-token.service';
|
||||||
@ -28,10 +30,17 @@ export class JuniorService {
|
|||||||
@Transactional()
|
@Transactional()
|
||||||
async createJuniors(body: CreateJuniorRequestDto, guardianId: string) {
|
async createJuniors(body: CreateJuniorRequestDto, guardianId: string) {
|
||||||
this.logger.log(`Creating junior for guardian ${guardianId}`);
|
this.logger.log(`Creating junior for guardian ${guardianId}`);
|
||||||
const existingUser = await this.userService.findUser([
|
|
||||||
{ email: body.email },
|
const searchConditions: FindOptionsWhere<User>[] = [{ email: body.email }];
|
||||||
{ phoneNumber: body.phoneNumber, countryCode: body.countryCode },
|
|
||||||
]);
|
if (body.phoneNumber && body.countryCode) {
|
||||||
|
searchConditions.push({
|
||||||
|
phoneNumber: body.phoneNumber,
|
||||||
|
countryCode: body.countryCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingUser = await this.userService.findUser(searchConditions);
|
||||||
|
|
||||||
if (existingUser) {
|
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} or phone number ${body.phoneNumber} already exists`);
|
||||||
|
|||||||
Reference in New Issue
Block a user