mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
feat: finalize update junior
This commit is contained in:
@ -4,6 +4,7 @@ import { Roles } from '~/auth/enums';
|
||||
import { CardService } from '~/card/services';
|
||||
import { NeoLeapService } from '~/common/modules/neoleap/services';
|
||||
import { PageOptionsRequestDto } from '~/core/dtos';
|
||||
import { setIf } from '~/core/utils';
|
||||
import { CustomerService } from '~/customer/services';
|
||||
import { DocumentService, OciService } from '~/document/services';
|
||||
import { UserType } from '~/user/enums';
|
||||
@ -88,17 +89,14 @@ export class JuniorService {
|
||||
async updateJunior(juniorId: string, body: UpdateJuniorRequestDto, guardianId: string) {
|
||||
this.logger.log(`Updating junior ${juniorId}`);
|
||||
const junior = await this.findJuniorById(juniorId, false, guardianId);
|
||||
if (body.profilePictureId) {
|
||||
junior.customer.user.profilePictureId = body.profilePictureId;
|
||||
}
|
||||
if (body.firstName) {
|
||||
junior.customer.user.firstName = body.firstName;
|
||||
junior.customer.firstName = body.firstName;
|
||||
}
|
||||
if (body.lastName) {
|
||||
junior.customer.user.lastName = body.lastName;
|
||||
junior.customer.lastName = body.lastName;
|
||||
const customer = junior.customer;
|
||||
const user = customer.user;
|
||||
|
||||
if (user.password) {
|
||||
this.logger.error(`Cannot update junior ${juniorId} with registered user`);
|
||||
throw new BadRequestException('JUNIOR.CANNOT_UPDATE_REGISTERED_USER');
|
||||
}
|
||||
|
||||
if (body.email) {
|
||||
const existingUser = await this.userService.findUser({ email: body.email });
|
||||
if (existingUser && existingUser.id !== junior.customer.user.id) {
|
||||
@ -107,16 +105,16 @@ export class JuniorService {
|
||||
}
|
||||
junior.customer.user.email = body.email;
|
||||
}
|
||||
setIf(user, 'profilePictureId', body.profilePictureId);
|
||||
setIf(user, 'firstName', body.firstName);
|
||||
setIf(user, 'lastName', body.lastName);
|
||||
|
||||
if (body.dateOfBirth) {
|
||||
junior.customer.dateOfBirth = body.dateOfBirth;
|
||||
}
|
||||
if (body.relationship) {
|
||||
junior.relationship = body.relationship;
|
||||
}
|
||||
console.log('++++++');
|
||||
setIf(customer, 'firstName', body.firstName);
|
||||
setIf(customer, 'lastName', body.lastName);
|
||||
setIf(customer, 'dateOfBirth', body.dateOfBirth as unknown as Date);
|
||||
|
||||
await Promise.all([junior.save(), junior.customer.user.save(), junior.customer.save()]);
|
||||
setIf(junior, 'relationship', body.relationship);
|
||||
await Promise.all([junior.save(), customer.save(), user.save()]);
|
||||
this.logger.log(`Junior ${juniorId} updated successfully`);
|
||||
return junior;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user