diff --git a/src/users/controllers/users.controller.ts b/src/users/controllers/users.controller.ts index aadd984b1e1f8034831b3c139a7e9f0d33e42b6f..66804c1c8540ab9f4334da1f11d1ec0074fda4bd 100644 --- a/src/users/controllers/users.controller.ts +++ b/src/users/controllers/users.controller.ts @@ -78,7 +78,7 @@ export class UsersController { this.logger.warn(`Job does not exist: ${profile.jobName}`); throw new HttpException('Job does not exist', HttpStatus.BAD_REQUEST); } - await this.usersService.updateUserProfile(req.user._id, employerDocument, jobDocument); + await this.usersService.updateUserProfile(req.user._id, employerDocument, jobDocument, profile.withAppointment); return this.usersService.findOne(req.user.email); } diff --git a/src/users/dto/profile.dto.ts b/src/users/dto/profile.dto.ts index ad0563c6969ad3844fe203cdebd385dbf704e0b2..fd85a5e5baf5eb054dc6733e385d62a4bcd0b412 100644 --- a/src/users/dto/profile.dto.ts +++ b/src/users/dto/profile.dto.ts @@ -1,4 +1,4 @@ -import { IsNotEmpty, IsString } from 'class-validator'; +import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator'; export class ProfileDto { @IsNotEmpty() @@ -8,4 +8,8 @@ export class ProfileDto { @IsNotEmpty() @IsString() jobName: string; + + @IsOptional() + @IsBoolean() + withAppointment?: boolean; } diff --git a/src/users/services/users.service.ts b/src/users/services/users.service.ts index 6dd7ac77a98420ec5f66de17797a0f0fef655936..038b6d6d73c04a94677608a556952a624cafb452 100644 --- a/src/users/services/users.service.ts +++ b/src/users/services/users.service.ts @@ -796,11 +796,22 @@ export class UsersService { * @param employer * @param job */ - public async updateUserProfile(userId: Types.ObjectId, employer: EmployerDocument, job: JobDocument): Promise<IUser> { + public async updateUserProfile( + userId: Types.ObjectId, + employer: EmployerDocument, + job: JobDocument, + withAppointment?: boolean + ): Promise<IUser> { this.logger.debug(`updateUserProfile | ${userId}`); const updated = await this.userModel - .findByIdAndUpdate({ _id: userId }, { $set: { employer: employer._id, job: job._id } }) + .findByIdAndUpdate({ _id: userId }, { $set: { employer: employer._id, job: job._id } }, { new: true }) + .populate('job') .exec(); + if (updated?.job?.hasPersonalOffer && withAppointment !== undefined) { + updated.withAppointment = withAppointment; + await updated.save(); + } + if (updated) { const populatedResult = await this.findPopulatedUserRegistryById(updated._id); this.userRegistrySearchService.update(populatedResult);