mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
Add delete user invitation functionality
This commit is contained in:
@ -2,6 +2,7 @@ import { InviteUserService } from '../services/invite-user.service';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
@ -114,4 +115,17 @@ export class InviteUserController {
|
||||
invitedUserUuid,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete(':invitedUserUuid')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.INVITE_USER.ACTIONS.DELETE_USER_INVITATION_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.INVITE_USER.ACTIONS.DELETE_USER_INVITATION_DESCRIPTION,
|
||||
})
|
||||
async deleteUserInvitation(
|
||||
@Param('invitedUserUuid') invitedUserUuid: string,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.inviteUserService.deleteUserInvitation(invitedUserUuid);
|
||||
}
|
||||
}
|
||||
|
@ -524,10 +524,11 @@ export class InviteUserService {
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
await this.emailService.sendEmailWithDisableOrEnableTemplate(
|
||||
await this.emailService.sendEmailWithTemplate(
|
||||
userData.email,
|
||||
userData.firstName,
|
||||
disable,
|
||||
false,
|
||||
);
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
@ -611,4 +612,69 @@ export class InviteUserService {
|
||||
|
||||
await Promise.allSettled(associatePromises);
|
||||
}
|
||||
|
||||
async deleteUserInvitation(
|
||||
invitedUserUuid: string,
|
||||
): Promise<BaseResponseDto> {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
const userData = await this.inviteUserRepository.findOne({
|
||||
where: { uuid: invitedUserUuid },
|
||||
relations: ['roleType', 'spaces.space', 'project'],
|
||||
});
|
||||
|
||||
if (!userData) {
|
||||
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
if (userData.status === UserStatusEnum.INVITED) {
|
||||
await this.inviteUserRepository.update(
|
||||
{ uuid: invitedUserUuid },
|
||||
{ isActive: false },
|
||||
);
|
||||
} else if (userData.status === UserStatusEnum.ACTIVE) {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { inviteUser: { uuid: invitedUserUuid } },
|
||||
relations: ['userSpaces.space', 'userSpaces.space.community'],
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new HttpException(
|
||||
'User account not found',
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
await this.disassociateUserFromSpaces(user, userData.project.uuid);
|
||||
await this.inviteUserRepository.update(
|
||||
{ uuid: invitedUserUuid },
|
||||
{ isActive: false },
|
||||
);
|
||||
await this.userRepository.update(
|
||||
{ uuid: user.uuid },
|
||||
{ isActive: false },
|
||||
);
|
||||
}
|
||||
await this.emailService.sendEmailWithTemplate(
|
||||
userData.email,
|
||||
userData.firstName,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
return new SuccessResponseDto({
|
||||
statusCode: HttpStatus.OK,
|
||||
success: true,
|
||||
message: 'User invitation deleted successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user