Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class RemoveUserFromGroupUseCase
protected async implementation(inputData: AddUserInGroupDs): Promise<RemoveUserFromGroupResultDs> {
const { groupId } = inputData;
const email = inputData.email.toLowerCase();
const foundUser = await this._dbContext.userRepository.findOneUserByEmail(email);
const foundUser = await this._dbContext.userRepository.findOneUserByEmailAndGroupId(email, groupId);
if (!foundUser) {
throw new HttpException(
{
Expand All @@ -47,6 +47,14 @@ export class RemoveUserFromGroupUseCase
return e.id;
})
.indexOf(foundUser.id);
if (delIndex === -1) {
throw new HttpException(
{
message: Messages.USER_NOT_FOUND,
},
HttpStatus.NOT_FOUND,
);
}
groupToUpdate.users.splice(delIndex, 1);
const updatedGroup = await this._dbContext.groupRepository.saveNewOrUpdatedGroup(groupToUpdate);
return buildRemoveUserFromGroupResultDs(updatedGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export const userCustomRepositoryExtension: IUserRepository = {
return userQb.getOne();
},

async findOneUserByEmailAndGroupId(email: string, groupId: string): Promise<UserEntity> {
const userQb = this.createQueryBuilder('user')
.leftJoinAndSelect('user.groups', 'group')
.where('user.email = :userEmail', { userEmail: email?.toLowerCase() })
.andWhere('group.id = :groupId', { groupId: groupId });
return await userQb.getOne();
},

async findOneUserWithEmailVerification(userId: string): Promise<UserEntity> {
const usersQb = this.createQueryBuilder('user')
.leftJoinAndSelect('user.email_verification', 'email_verification')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ export interface IUserRepository {
unSuspendUsers(userIds: Array<string>): Promise<Array<UserEntity>>;

bulkSaveUpdatedUsers(updatedUsers: Array<UserEntity>): Promise<Array<UserEntity>>;

findOneUserByEmailAndGroupId(email: string, groupId: string): Promise<UserEntity>;
}
Loading