mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 19:34:53 +00:00
Add app agreement acceptance check and validation
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user