mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
feat: update junior
This commit is contained in:
@ -9,7 +9,7 @@ import { DocumentService, OciService } from '~/document/services';
|
||||
import { UserType } from '~/user/enums';
|
||||
import { UserService } from '~/user/services';
|
||||
import { UserTokenService } from '~/user/services/user-token.service';
|
||||
import { CreateJuniorRequestDto, SetThemeRequestDto } from '../dtos/request';
|
||||
import { CreateJuniorRequestDto, SetThemeRequestDto, UpdateJuniorRequestDto } from '../dtos/request';
|
||||
import { Junior } from '../entities';
|
||||
import { JuniorRepository } from '../repositories';
|
||||
import { QrcodeService } from './qrcode.service';
|
||||
@ -85,6 +85,42 @@ export class JuniorService {
|
||||
return junior;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (body.email) {
|
||||
const existingUser = await this.userService.findUser({ email: body.email });
|
||||
if (existingUser && existingUser.id !== junior.customer.user.id) {
|
||||
this.logger.error(`User with email ${body.email} already exists`);
|
||||
throw new BadRequestException('USER.ALREADY_EXISTS');
|
||||
}
|
||||
junior.customer.user.email = body.email;
|
||||
}
|
||||
|
||||
if (body.dateOfBirth) {
|
||||
junior.customer.dateOfBirth = body.dateOfBirth;
|
||||
}
|
||||
if (body.relationship) {
|
||||
junior.relationship = body.relationship;
|
||||
}
|
||||
console.log('++++++');
|
||||
|
||||
await Promise.all([junior.save(), junior.customer.user.save(), junior.customer.save()]);
|
||||
this.logger.log(`Junior ${juniorId} updated successfully`);
|
||||
return junior;
|
||||
}
|
||||
|
||||
@Transactional()
|
||||
async setTheme(body: SetThemeRequestDto, juniorId: string) {
|
||||
this.logger.log(`Setting theme for junior ${juniorId}`);
|
||||
|
||||
Reference in New Issue
Block a user