Skip to content

Commit

Permalink
fix: get workspace owner from the apiserver
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Nov 25, 2023
1 parent 7e95cfc commit f9ac171
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
11 changes: 11 additions & 0 deletions mods/apiserver/src/workspaces/getMembersByWorkspaceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export async function getMembersByWorkspaceId(
id: workspaceId
},
include: {
owner: true,
members: {
include: {
user: true
Expand All @@ -62,6 +63,16 @@ export async function getMembersByWorkspaceId(
};
});

members.unshift({
id: workspace.owner.id,
userId: workspace.owner.id,
name: workspace.owner.name,
email: workspace.owner.email,
status: WorkspaceMemberStatus.ACTIVE,
role: WorkspaceMemberRole.OWNER,
createdAt: workspace.owner.createdAt
});

return {
members
};
Expand Down
30 changes: 16 additions & 14 deletions mods/apiserver/test/workspaces.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ describe("@apiserver[workspaces]", () => {
prisma: {
workspace: {
findUnique: sandbox.stub().resolves({
members: [testMember]
members: [testMember],
owner: {
id: "c5a6a3a6-fe03-4b10-9313-62b46dc11111",
name: "Jane Doe",
email: "[email protected]",
createdAt: new Date()
}
})
}
}
Expand All @@ -141,21 +147,17 @@ describe("@apiserver[workspaces]", () => {
);

// Act
const members = await getMembersByWorkspaceId(ctx, request);
const result = await getMembersByWorkspaceId(ctx, request);

// Assert
chai.expect(members).to.deep.equal({
members: [
{
id: testMember.id,
userId: testMember.userId,
email: testMember.user.email,
name: testMember.user.name,
status: testMember.status,
role: testMember.role,
createdAt: testMember.createdAt
}
]
chai.expect(result.members[1]).to.deep.equal({
id: testMember.id,
userId: testMember.userId,
email: testMember.user.email,
name: testMember.user.name,
status: testMember.status,
role: testMember.role,
createdAt: testMember.createdAt
});
});

Expand Down
17 changes: 2 additions & 15 deletions mods/frontoffice/src/containers/SettingsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,10 @@ function SettingsContainer() {

const workspaces = new SDK.Workspaces(client);

// Initialize members with owner data
const ownerMember = {
id: userSettings.id,
userId: userSettings.id,
name: userSettings.name,
email: userSettings.email,
role: Role.OWNER,
status: Status.ACTIVE,
createdAt: new Date(userSettings.createdAt)
};

setMembers([ownerMember]); // set initial state with only the owner

workspaces
.getMembersByWorkspaceId(workspaceId)
.then((response) => {
const newMembers = response.members.map((member) => ({
const members = response.members.map((member) => ({
id: member.id,
userId: member.userId,
name: member.name,
Expand All @@ -150,7 +137,7 @@ function SettingsContainer() {
createdAt: new Date(member.createdAt)
}));

setMembers((prevMembers) => [prevMembers[0], ...newMembers]);
setMembers(members);
})
.catch((err) => {
logger.error("error getting workspace members", err);
Expand Down

0 comments on commit f9ac171

Please sign in to comment.