mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
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:
@ -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 },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user