mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
Merge pull request #40 from HamzaSha1/ZOD-339-child-profile-gender-update-is-not-reflected-after-editing
Zod 339 child profile gender update is not reflected after editing
This commit is contained in:
@ -120,6 +120,7 @@ export class JuniorService {
|
||||
setIf(customer, 'firstName', body.firstName);
|
||||
setIf(customer, 'lastName', body.lastName);
|
||||
setIf(customer, 'dateOfBirth', body.dateOfBirth as unknown as Date);
|
||||
setIf(customer, 'gender', body.gender);
|
||||
|
||||
setIf(junior, 'relationship', body.relationship);
|
||||
await Promise.all([junior.save(), customer.save(), user.save()]);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { IsDateString, IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { Gender } from '~/customer/enums';
|
||||
export class UpdateUserRequestDto {
|
||||
@ApiProperty({ example: 'John' })
|
||||
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'user.firstName' }) })
|
||||
@ -18,4 +19,14 @@ export class UpdateUserRequestDto {
|
||||
@IsUUID('4', { message: i18n('validation.IsUUID', { path: 'general', property: 'user.profilePictureId' }) })
|
||||
@IsOptional()
|
||||
profilePictureId!: string;
|
||||
|
||||
@ApiPropertyOptional({ enum: Gender })
|
||||
@IsEnum(Gender, { message: i18n('validation.IsEnum', { path: 'general', property: 'customer.gender' }) })
|
||||
@IsOptional()
|
||||
gender!: Gender;
|
||||
|
||||
@ApiPropertyOptional({ example: '2020-01-01' })
|
||||
@IsDateString({}, { message: i18n('validation.IsDateString', { path: 'general', property: 'customer.dateOfBirth' }) })
|
||||
@IsOptional()
|
||||
dateOfBirth!: Date;
|
||||
}
|
||||
|
||||
@ -192,11 +192,25 @@ export class UserService {
|
||||
await this.validateProfilePictureId(data.profilePictureId, userId);
|
||||
|
||||
this.logger.log(`Updating user ${userId} with data ${JSON.stringify(data)}`);
|
||||
const { affected } = await this.userRepository.update(userId, data);
|
||||
|
||||
const { gender, dateOfBirth, ...userData } = data;
|
||||
|
||||
const { affected } = await this.userRepository.update(userId, userData);
|
||||
if (affected === 0) {
|
||||
this.logger.error(`User with id ${userId} not found`);
|
||||
throw new BadRequestException('USER.NOT_FOUND');
|
||||
}
|
||||
|
||||
if (gender !== undefined || dateOfBirth !== undefined) {
|
||||
const customerData: Partial<{ gender: typeof gender; dateOfBirth: Date }> = {};
|
||||
if (gender !== undefined) {
|
||||
customerData.gender = gender;
|
||||
}
|
||||
if (dateOfBirth !== undefined) {
|
||||
customerData.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
await this.customerService.updateCustomer(userId, customerData);
|
||||
}
|
||||
}
|
||||
|
||||
async updateUserEmail(userId: string, email: string) {
|
||||
|
||||
Reference in New Issue
Block a user