mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +10:00
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import type { TeamMemberRole } from '@documenso/prisma/client';
|
|
|
|
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '../../constants/teams';
|
|
|
|
export type UpdateTeamMemberOptions = {
|
|
userId: number;
|
|
teamId: number;
|
|
teamMemberId: number;
|
|
data: {
|
|
role: TeamMemberRole;
|
|
};
|
|
};
|
|
|
|
export const updateTeamMember = async ({
|
|
userId,
|
|
teamId,
|
|
teamMemberId,
|
|
data,
|
|
}: UpdateTeamMemberOptions) => {
|
|
await prisma.$transaction(async (tx) => {
|
|
// Find the team and validate that the user is allowed to update members.
|
|
const team = await tx.team.findFirstOrThrow({
|
|
where: {
|
|
id: teamId,
|
|
members: {
|
|
some: {
|
|
userId,
|
|
role: {
|
|
in: TEAM_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_TEAM'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return await tx.teamMember.update({
|
|
where: {
|
|
id: teamMemberId,
|
|
teamId,
|
|
userId: {
|
|
not: team.ownerUserId,
|
|
},
|
|
},
|
|
data: {
|
|
role: data.role,
|
|
},
|
|
});
|
|
});
|
|
};
|