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, }, }); }); };