mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
- Added functionality to decline team invitations - Added email notifications for when team is deleted - Added email notifications for team members joining and leaving
35 lines
745 B
TypeScript
35 lines
745 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
|
|
export type DeclineTeamInvitationOptions = {
|
|
userId: number;
|
|
teamId: number;
|
|
};
|
|
|
|
export const declineTeamInvitation = async ({ userId, teamId }: DeclineTeamInvitationOptions) => {
|
|
await prisma.$transaction(
|
|
async (tx) => {
|
|
const user = await tx.user.findFirstOrThrow({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
});
|
|
|
|
const teamMemberInvite = await tx.teamMemberInvite.findFirstOrThrow({
|
|
where: {
|
|
teamId,
|
|
email: user.email,
|
|
},
|
|
});
|
|
|
|
await tx.teamMemberInvite.delete({
|
|
where: {
|
|
id: teamMemberInvite.id,
|
|
},
|
|
});
|
|
|
|
// TODO: notify the team owner
|
|
},
|
|
{ timeout: 30_000 },
|
|
);
|
|
};
|