feat: set roleId when inviting new members
This commit is contained in:
@@ -117,12 +117,20 @@ export const memberRouter = createTRPCRouter({
|
|||||||
|
|
||||||
const existingUser = await userRepo.getByEmail(ctx.db, input.email);
|
const existingUser = await userRepo.getByEmail(ctx.db, input.email);
|
||||||
|
|
||||||
|
// Get the workspace role to set roleId
|
||||||
|
const memberRole = await permissionRepo.getRoleByWorkspaceIdAndName(
|
||||||
|
ctx.db,
|
||||||
|
workspace.id,
|
||||||
|
"member",
|
||||||
|
);
|
||||||
|
|
||||||
const invite = await memberRepo.create(ctx.db, {
|
const invite = await memberRepo.create(ctx.db, {
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
email: input.email,
|
email: input.email,
|
||||||
userId: existingUser?.id ?? null,
|
userId: existingUser?.id ?? null,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
role: "member",
|
role: "member",
|
||||||
|
roleId: memberRole?.id ?? null,
|
||||||
status: "invited",
|
status: "invited",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -636,12 +644,20 @@ export const memberRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the workspace role to set roleId
|
||||||
|
const memberRole = await permissionRepo.getRoleByWorkspaceIdAndName(
|
||||||
|
ctx.db,
|
||||||
|
invite.workspaceId,
|
||||||
|
"member",
|
||||||
|
);
|
||||||
|
|
||||||
await memberRepo.create(ctx.db, {
|
await memberRepo.create(ctx.db, {
|
||||||
workspaceId: invite.workspaceId,
|
workspaceId: invite.workspaceId,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
createdBy: user.id,
|
createdBy: user.id,
|
||||||
role: "member",
|
role: "member",
|
||||||
|
roleId: memberRole?.id ?? null,
|
||||||
status: "active",
|
status: "active",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export const create = async (
|
|||||||
workspaceId: number;
|
workspaceId: number;
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
role: MemberRole;
|
role: MemberRole;
|
||||||
|
roleId?: number | null;
|
||||||
status: MemberStatus;
|
status: MemberStatus;
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
@@ -39,6 +40,7 @@ export const create = async (
|
|||||||
workspaceId: memberInput.workspaceId,
|
workspaceId: memberInput.workspaceId,
|
||||||
createdBy: memberInput.createdBy,
|
createdBy: memberInput.createdBy,
|
||||||
role: memberInput.role,
|
role: memberInput.role,
|
||||||
|
roleId: memberInput.roleId ?? null,
|
||||||
status: memberInput.status,
|
status: memberInput.status,
|
||||||
})
|
})
|
||||||
.returning({
|
.returning({
|
||||||
|
|||||||
Reference in New Issue
Block a user