Skip to content

Commit

Permalink
Refactor deleteGroup method and add getUsersInGroup method
Browse files Browse the repository at this point in the history
This commit refactors the `deleteGroup` method in the `BlurtingService` class to use the `getUsersInGroup` method instead of `getGroupUsers`. Additionally, a new method `getUsersInGroup` is added to the `UserService` class to retrieve users belonging to a specific group.
  • Loading branch information
overthestream committed Jan 19, 2024
1 parent 76207d8 commit 8f44b0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/blurting/blurting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class BlurtingService {
}

async deleteGroup(group: BlurtingGroupEntity) {
const users = await this.userService.getGroupUsers(group.id);
const users = await this.userService.getUsersInGroup(group.id);
for (const user of users) {
user.group = null;
}
Expand Down
8 changes: 8 additions & 0 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export class UserService {
private readonly roomModel: Model<Room>,
) {}

async getUsersInGroup(groupId: number) {
const users = await this.userRepository.find({
where: { group: { id: groupId } },
relations: ['userInfo', 'group'],
});
return users;
}

async getGroupUsers(userId: number) {
const user = await this.userRepository.findOne({
where: { id: userId },
Expand Down

0 comments on commit 8f44b0a

Please sign in to comment.