Add app agreement acceptance check and validation

This commit is contained in:
faris Aljohari
2025-01-22 00:34:47 -06:00
parent 41da528963
commit 6dd6c79d87
3 changed files with 34 additions and 4 deletions

View File

@ -1,5 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import {
IsBoolean,
IsEmail,
IsNotEmpty,
IsOptional,
IsString,
} from 'class-validator';
import { IsPasswordStrong } from 'src/validators/password.validator';
export class UserSignUpDto {
@ -39,7 +45,19 @@ export class UserSignUpDto {
@IsNotEmpty()
public lastName: string;
@ApiProperty({
description: 'regionUuid',
required: false,
})
@IsString()
@IsOptional()
public regionUuid?: string;
@ApiProperty({
description: 'hasAcceptedAppAgreement',
required: true,
})
@IsBoolean()
@IsNotEmpty()
public hasAcceptedAppAgreement: boolean;
}

View File

@ -46,12 +46,17 @@ export class UserAuthService {
);
try {
const { regionUuid, ...rest } = userSignUpDto;
const { regionUuid, hasAcceptedAppAgreement, ...rest } = userSignUpDto;
if (!hasAcceptedAppAgreement) {
throw new BadRequestException('Please accept the terms and conditions');
}
const spaceMemberRole = await this.roleService.findRoleByType(
RoleType.SPACE_MEMBER,
);
const user = await this.userRepository.save({
...rest,
appAgreementAcceptedAt: new Date(),
hasAcceptedAppAgreement,
password: hashedPassword,
roleType: { uuid: spaceMemberRole.uuid },
region: regionUuid
@ -65,7 +70,7 @@ export class UserAuthService {
return user;
} catch (error) {
throw new BadRequestException('Failed to register user');
throw new BadRequestException(error.message || 'Failed to register user');
}
}
@ -116,6 +121,7 @@ export class UserAuthService {
firstName: googleUserData['given_name'],
lastName: googleUserData['family_name'],
password: googleUserData['email'],
hasAcceptedAppAgreement: true,
});
}
data.email = googleUserData['email'];
@ -147,6 +153,8 @@ export class UserAuthService {
userId: user.uuid,
uuid: user.uuid,
role: user.roleType,
hasAcceptedWebAgreement: user.hasAcceptedWebAgreement,
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
sessionId: session[1].uuid,
});
return res;