mirror of
https://github.com/documenso/documenso.git
synced 2025-11-17 10:11:35 +10:00
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '@documenso/lib/constants/teams';
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
export type DeleteTeamEmailOptions = {
|
|
userId: number;
|
|
userEmail: string;
|
|
teamId: number;
|
|
};
|
|
|
|
/**
|
|
* Delete a team email.
|
|
*
|
|
* The user must either be part of the team with the required permissions, or the owner of the email.
|
|
*/
|
|
export const deleteTeamEmail = async ({ userId, userEmail, teamId }: DeleteTeamEmailOptions) => {
|
|
await prisma.$transaction(async (tx) => {
|
|
await tx.team.findFirstOrThrow({
|
|
where: {
|
|
id: teamId,
|
|
OR: [
|
|
{
|
|
teamEmail: {
|
|
email: userEmail,
|
|
},
|
|
},
|
|
{
|
|
members: {
|
|
some: {
|
|
userId,
|
|
role: {
|
|
in: TEAM_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_TEAM'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
await tx.teamEmail.delete({
|
|
where: {
|
|
teamId,
|
|
},
|
|
});
|
|
});
|
|
};
|