chore: team stuff (#1228)

- Added functionality to decline team invitations
- Added email notifications for when team is deleted
- Added email notifications for team members joining and leaving
This commit is contained in:
Ephraim Duncan
2024-07-25 04:27:19 +00:00
committed by GitHub
parent b366ab8736
commit a8febae87e
44 changed files with 1014 additions and 226 deletions

View File

@ -2,6 +2,8 @@ import { updateSubscriptionItemQuantity } from '@documenso/ee/server-only/stripe
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
import { prisma } from '@documenso/prisma';
import { jobs } from '../../jobs/client';
export type LeaveTeamOptions = {
/**
* The ID of the user who is leaving the team.
@ -23,12 +25,21 @@ export const leaveTeam = async ({ userId, teamId }: LeaveTeamOptions) => {
ownerUserId: {
not: userId,
},
members: {
some: {
userId,
},
},
},
include: {
subscription: true,
},
});
const leavingUser = await tx.user.findUniqueOrThrow({
where: { id: userId },
});
await tx.teamMember.delete({
where: {
userId_teamId: {
@ -56,6 +67,14 @@ export const leaveTeam = async ({ userId, teamId }: LeaveTeamOptions) => {
quantity: numberOfSeats,
});
}
await jobs.triggerJob({
name: 'send.team-member-left.email',
payload: {
teamId,
memberUserId: leavingUser.id,
},
});
},
{ timeout: 30_000 },
);