From f675064b68c4bf769ba39c17f4b9fb4a5e82c5ee Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Wed, 22 Jan 2025 00:34:54 -0600 Subject: [PATCH] Add endpoint to update user web agreement --- libs/common/src/constants/controller-route.ts | 4 +++ src/users/controllers/user.controller.ts | 16 +++++++++++ src/users/services/user-space.service.ts | 5 +--- src/users/services/user.service.ts | 27 +++++++++++++++---- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/libs/common/src/constants/controller-route.ts b/libs/common/src/constants/controller-route.ts index d82aebe..4cee3fe 100644 --- a/libs/common/src/constants/controller-route.ts +++ b/libs/common/src/constants/controller-route.ts @@ -349,6 +349,10 @@ export class ControllerRoute { public static readonly DELETE_USER_SUMMARY = 'Delete user by UUID'; public static readonly DELETE_USER_DESCRIPTION = 'This endpoint deletes a user identified by their UUID. Accessible only by users with the Super Admin role.'; + public static readonly UPDATE_USER_WEB_AGREEMENT_SUMMARY = + 'Update user web agreement by user UUID'; + public static readonly UPDATE_USER_WEB_AGREEMENT_DESCRIPTION = + 'This endpoint updates the web agreement for a user identified by their UUID.'; }; }; static AUTHENTICATION = class { diff --git a/src/users/controllers/user.controller.ts b/src/users/controllers/user.controller.ts index 6f0eded..ce9991a 100644 --- a/src/users/controllers/user.controller.ts +++ b/src/users/controllers/user.controller.ts @@ -5,6 +5,7 @@ import { Get, HttpStatus, Param, + Patch, Put, UseGuards, } from '@nestjs/common'; @@ -21,6 +22,7 @@ import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard'; import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard'; import { EnableDisableStatusEnum } from '@app/common/constants/days.enum'; import { ControllerRoute } from '@app/common/constants/controller-route'; +import { BaseResponseDto } from '@app/common/dto/base.response.dto'; @ApiTags('User Module') @Controller({ @@ -151,4 +153,18 @@ export class UserController { message: 'User deleted successfully', }; } + + @ApiBearerAuth() + @UseGuards(JwtAuthGuard) + @Patch('agreements/web/:userUuid') + @ApiOperation({ + summary: ControllerRoute.USER.ACTIONS.UPDATE_USER_WEB_AGREEMENT_SUMMARY, + description: + ControllerRoute.USER.ACTIONS.UPDATE_USER_WEB_AGREEMENT_DESCRIPTION, + }) + async acceptWebAgreement( + @Param('userUuid') userUuid: string, + ): Promise { + return this.userService.acceptWebAgreement(userUuid); + } } diff --git a/src/users/services/user-space.service.ts b/src/users/services/user-space.service.ts index fc15c3d..e06bbd5 100644 --- a/src/users/services/user-space.service.ts +++ b/src/users/services/user-space.service.ts @@ -59,10 +59,7 @@ export class UserSpaceService { const { inviteCode } = params; try { const inviteSpace = await this.findInviteSpaceByInviteCode(inviteCode); - const user = await this.userService.getUserDetailsByUserUuid( - userUuid, - true, - ); + const user = await this.userService.getUserDetailsByUserUuid(userUuid); await this.checkSpaceMemberRole(user); await this.addUserToSpace(userUuid, inviteSpace.space.uuid); diff --git a/src/users/services/user.service.ts b/src/users/services/user.service.ts index 96a669b..268dc7c 100644 --- a/src/users/services/user.service.ts +++ b/src/users/services/user.service.ts @@ -15,6 +15,7 @@ import { RegionRepository } from '@app/common/modules/region/repositories'; import { TimeZoneRepository } from '@app/common/modules/timezone/repositories'; import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix'; import { UserEntity } from '@app/common/modules/user/entities'; +import { SuccessResponseDto } from '@app/common/dto/success.response.dto'; @Injectable() export class UserService { @@ -23,15 +24,13 @@ export class UserService { private readonly regionRepository: RegionRepository, private readonly timeZoneRepository: TimeZoneRepository, ) {} - async getUserDetailsByUserUuid(userUuid: string, withRole = false) { + async getUserDetailsByUserUuid(userUuid: string) { try { const user = await this.userRepository.findOne({ where: { uuid: userUuid, }, - ...(withRole - ? { relations: ['roleType'] } - : { relations: ['region', 'timezone'] }), + relations: ['region', 'timezone', 'roleType'], }); if (!user) { throw new BadRequestException('Invalid room UUID'); @@ -48,7 +47,11 @@ export class UserService { profilePicture: cleanedProfilePicture, region: user?.region, timeZone: user?.timezone, - ...(withRole && { role: user?.roleType }), + hasAcceptedWebAgreement: user?.hasAcceptedWebAgreement, + webAgreementAcceptedAt: user?.webAgreementAcceptedAt, + hasAcceptedAppAgreement: user?.hasAcceptedAppAgreement, + appAgreementAcceptedAt: user?.appAgreementAcceptedAt, + role: user?.roleType, }; } catch (err) { if (err instanceof BadRequestException) { @@ -241,6 +244,20 @@ export class UserService { ); } } + async acceptWebAgreement(userUuid: string) { + await this.userRepository.update( + { uuid: userUuid }, + { + hasAcceptedWebAgreement: true, + webAgreementAcceptedAt: new Date(), + }, + ); + return new SuccessResponseDto({ + statusCode: HttpStatus.OK, + success: true, + message: 'Web agreement accepted successfully', + }); + } async findOneById(id: string): Promise { return await this.userRepository.findOne({ where: { uuid: id } }); }