Skip to content

Commit

Permalink
hotfix: team billing on batch operations (#15570)
Browse files Browse the repository at this point in the history
Co-authored-by: sean-brydon <[email protected]>
  • Loading branch information
zomars and sean-brydon authored Jun 26, 2024
1 parent 3736791 commit d3246ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { updateQuantitySubscriptionFromStripe } from "@calcom/features/ee/teams/lib/payments";
import { isOrganisationAdmin } from "@calcom/lib/server/queries/organisations";
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
import { prisma } from "@calcom/prisma";
Expand Down Expand Up @@ -62,7 +63,7 @@ export async function bulkDeleteUsersHandler({ ctx, input }: BulkDeleteUsersHand
// We do this in a transaction to make sure that all memberships are removed before we remove the organization relation from the user
// We also do this to make sure that if one of the queries fail, the whole transaction fails
await prisma.$transaction([removeProfiles, deleteMany, removeOrgrelation]);

await updateQuantitySubscriptionFromStripe(currentUser.organizationId);
return {
success: true,
usersDeleted: input.userIds.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import type { TInviteMemberInputSchema } from "./inviteMember.schema";
import type { TeamWithParent } from "./types";
import {
checkPermissions,
getTeamOrThrow,
getUniqueUsernameOrEmailsOrThrow,
createMemberships,
createNewUsersConnectToOrgIfExists,
getExistingUsersToInvite,
getOrgConnectionInfo,
getOrgState,
sendSignupToOrganizationEmail,
getExistingUsersToInvite,
createNewUsersConnectToOrgIfExists,
createMemberships,
getTeamOrThrow,
getUniqueUsernameOrEmailsOrThrow,
groupUsersByJoinability,
sendExistingUserTeamInviteEmails,
sendEmails,
INVITE_STATUS,
sendEmails,
sendExistingUserTeamInviteEmails,
sendSignupToOrganizationEmail,
} from "./utils";

const log = logger.getSubLogger({ prefix: ["inviteMember.handler"] });
Expand Down Expand Up @@ -151,7 +151,7 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) =
isOrg: input.isOrg,
});
});
sendEmails(sendVerifEmailsPromises);
await sendEmails(sendVerifEmailsPromises);
}

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

if (IS_TEAM_BILLING_ENABLED) {
if (team.parentId) {
await updateQuantitySubscriptionFromStripe(team.parentId);
} else {
await updateQuantitySubscriptionFromStripe(input.teamId);
}
}
await handleSubscriptionUpdates(team.parentId || input.teamId);

return {
...input,
numUsersInvited:
existingUsersWithMembershipsThatNeedToBeInvited.length + newUsersEmailsOrUsernames.length,
};
};

async function handleSubscriptionUpdates(teamId: number) {
if (!IS_TEAM_BILLING_ENABLED) return;
await updateQuantitySubscriptionFromStripe(teamId);
}

export default inviteMemberHandler;

async function handleExistingUsersInvites({
Expand Down

0 comments on commit d3246ba

Please sign in to comment.