Skip to content

Commit d3246ba

Browse files
zomarssean-brydon
andauthored
hotfix: team billing on batch operations (#15570)
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
1 parent 3736791 commit d3246ba

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

packages/trpc/server/routers/viewer/organizations/bulkDeleteUsers.handler.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { updateQuantitySubscriptionFromStripe } from "@calcom/features/ee/teams/lib/payments";
12
import { isOrganisationAdmin } from "@calcom/lib/server/queries/organisations";
23
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
34
import { prisma } from "@calcom/prisma";
@@ -62,7 +63,7 @@ export async function bulkDeleteUsersHandler({ ctx, input }: BulkDeleteUsersHand
6263
// We do this in a transaction to make sure that all memberships are removed before we remove the organization relation from the user
6364
// We also do this to make sure that if one of the queries fail, the whole transaction fails
6465
await prisma.$transaction([removeProfiles, deleteMany, removeOrgrelation]);
65-
66+
await updateQuantitySubscriptionFromStripe(currentUser.organizationId);
6667
return {
6768
success: true,
6869
usersDeleted: input.userIds.length,

packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ import type { TInviteMemberInputSchema } from "./inviteMember.schema";
1818
import type { TeamWithParent } from "./types";
1919
import {
2020
checkPermissions,
21-
getTeamOrThrow,
22-
getUniqueUsernameOrEmailsOrThrow,
21+
createMemberships,
22+
createNewUsersConnectToOrgIfExists,
23+
getExistingUsersToInvite,
2324
getOrgConnectionInfo,
2425
getOrgState,
25-
sendSignupToOrganizationEmail,
26-
getExistingUsersToInvite,
27-
createNewUsersConnectToOrgIfExists,
28-
createMemberships,
26+
getTeamOrThrow,
27+
getUniqueUsernameOrEmailsOrThrow,
2928
groupUsersByJoinability,
30-
sendExistingUserTeamInviteEmails,
31-
sendEmails,
3229
INVITE_STATUS,
30+
sendEmails,
31+
sendExistingUserTeamInviteEmails,
32+
sendSignupToOrganizationEmail,
3333
} from "./utils";
3434

3535
const log = logger.getSubLogger({ prefix: ["inviteMember.handler"] });
@@ -151,7 +151,7 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) =
151151
isOrg: input.isOrg,
152152
});
153153
});
154-
sendEmails(sendVerifEmailsPromises);
154+
await sendEmails(sendVerifEmailsPromises);
155155
}
156156

157157
const organization = ctx.user.profile.organization;
@@ -166,20 +166,20 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) =
166166
orgSlug,
167167
});
168168

169-
if (IS_TEAM_BILLING_ENABLED) {
170-
if (team.parentId) {
171-
await updateQuantitySubscriptionFromStripe(team.parentId);
172-
} else {
173-
await updateQuantitySubscriptionFromStripe(input.teamId);
174-
}
175-
}
169+
await handleSubscriptionUpdates(team.parentId || input.teamId);
170+
176171
return {
177172
...input,
178173
numUsersInvited:
179174
existingUsersWithMembershipsThatNeedToBeInvited.length + newUsersEmailsOrUsernames.length,
180175
};
181176
};
182177

178+
async function handleSubscriptionUpdates(teamId: number) {
179+
if (!IS_TEAM_BILLING_ENABLED) return;
180+
await updateQuantitySubscriptionFromStripe(teamId);
181+
}
182+
183183
export default inviteMemberHandler;
184184

185185
async function handleExistingUsersInvites({

0 commit comments

Comments
 (0)