mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 00:14:54 +00:00
Refactor user and invited user validation in InviteUserService
This commit is contained in:
@ -181,29 +181,12 @@ export class InviteUserService {
|
|||||||
where: { email },
|
where: { email },
|
||||||
relations: ['project'],
|
relations: ['project'],
|
||||||
});
|
});
|
||||||
if (!user.isActive) {
|
this.validateUserOrInvite(user, 'User');
|
||||||
throw new HttpException('This user is deleted', HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
if (user?.project) {
|
|
||||||
throw new HttpException(
|
|
||||||
'This email already has a project',
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const invitedUser = await this.inviteUserRepository.findOne({
|
const invitedUser = await this.inviteUserRepository.findOne({
|
||||||
where: { email },
|
where: { email },
|
||||||
relations: ['project'],
|
relations: ['project'],
|
||||||
});
|
});
|
||||||
if (!invitedUser.isActive) {
|
this.validateUserOrInvite(invitedUser, 'Invited User');
|
||||||
throw new HttpException('This user is deleted', HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
if (invitedUser?.project) {
|
|
||||||
throw new HttpException(
|
|
||||||
'This email already has a project',
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SuccessResponseDto({
|
return new SuccessResponseDto({
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
@ -219,6 +202,24 @@ export class InviteUserService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private validateUserOrInvite(user: any, userType: string): void {
|
||||||
|
if (user) {
|
||||||
|
if (!user.isActive) {
|
||||||
|
throw new HttpException(
|
||||||
|
`${userType} is deleted`,
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (user.project) {
|
||||||
|
throw new HttpException(
|
||||||
|
`${userType} already has a project`,
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async activationCode(dto: ActivateCodeDto): Promise<BaseResponseDto> {
|
async activationCode(dto: ActivateCodeDto): Promise<BaseResponseDto> {
|
||||||
const { activationCode, userUuid } = dto;
|
const { activationCode, userUuid } = dto;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user