mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
Merge pull request #247 from SyncrowIOT/fix-delted-user-error
Refactor user and invited user validation in InviteUserService
This commit is contained in:
@ -181,29 +181,12 @@ export class InviteUserService {
|
||||
where: { email },
|
||||
relations: ['project'],
|
||||
});
|
||||
if (!user?.isActive) {
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
this.validateUserOrInvite(user, 'User');
|
||||
const invitedUser = await this.inviteUserRepository.findOne({
|
||||
where: { email },
|
||||
relations: ['project'],
|
||||
});
|
||||
if (!invitedUser?.isActive) {
|
||||
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,
|
||||
);
|
||||
}
|
||||
this.validateUserOrInvite(invitedUser, 'Invited User');
|
||||
|
||||
return new SuccessResponseDto({
|
||||
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> {
|
||||
const { activationCode, userUuid } = dto;
|
||||
|
||||
|
Reference in New Issue
Block a user