Skip to content

Commit 391690b

Browse files
authored
Merge pull request #62 from import-ai/bug
fix(role): expose role field
2 parents d02dc00 + 20a1ebb commit 391690b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/groups/dto/group-user.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ export class GroupUserDto {
1515
@IsString()
1616
@IsNotEmpty()
1717
email: string;
18+
19+
@Expose()
20+
@IsString()
21+
@IsNotEmpty()
22+
role: string;
1823
}

src/groups/groups.service.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GroupUser } from './entities/group-user.entity';
66
import { CreateGroupDto } from './dto/create-group.dto';
77
import { UpdateGroupDto } from './dto/update-group.dto';
88
import { User } from 'src/user/user.entity';
9+
import { NamespacesService } from 'src/namespaces/namespaces.service';
910

1011
@Injectable()
1112
export class GroupsService {
@@ -15,6 +16,7 @@ export class GroupsService {
1516
@InjectRepository(GroupUser)
1617
private readonly groupUserRepository: Repository<GroupUser>,
1718
private readonly dataSource: DataSource,
19+
private readonly namespaceService: NamespacesService,
1820
) {}
1921

2022
async listGroups(namespaceId: string): Promise<Group[]> {
@@ -91,14 +93,25 @@ export class GroupsService {
9193
}
9294

9395
async listGroupUsers(namespaceId: string, groupId: string): Promise<User[]> {
94-
const users = await this.groupUserRepository.find({
96+
const groupUsers = await this.groupUserRepository.find({
9597
where: {
9698
namespace: { id: namespaceId },
9799
group: { id: groupId },
98100
},
99101
relations: ['user'],
100102
});
101-
return users.map((user) => user.user);
103+
return await Promise.all(
104+
groupUsers.map((groupUser) =>
105+
this.namespaceService
106+
.getMemberByUserId(namespaceId, groupUser.user.id)
107+
.then((member) =>
108+
Promise.resolve({
109+
role: member ? member.role : 'member',
110+
...groupUser.user,
111+
}),
112+
),
113+
),
114+
);
102115
}
103116

104117
async addGroupUser(

0 commit comments

Comments
 (0)