Files
fc3815a150 fix: show personal credits even when user is on teams plan (#27511)
* show personal credits even if on team plan

* show personal credits even when on teams plan

* fix learn more link

---------

Co-authored-by: CarinaWolli <[email protected]>
2026-02-03 10:02:14 +01:00

42 lines
1.4 KiB
TypeScript

import { TeamService } from "@calcom/features/ee/teams/services/teamService";
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
import { MembershipRole } from "@calcom/prisma/enums";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
import { TRPCError } from "@trpc/server";
import type { TGetAllCreditsSchema } from "./getAllCredits.schema";
type GetAllCreditsOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TGetAllCreditsSchema;
};
export const getAllCreditsHandler = async ({ ctx, input }: GetAllCreditsOptions) => {
const { teamId } = input;
if (teamId) {
const team = await TeamService.fetchTeamOrThrow(teamId);
const permissionService = new PermissionCheckService();
const hasManageBillingPermission = await permissionService.checkPermission({
userId: ctx.user.id,
teamId,
permission: team.isOrganization ? "organization.manageBilling" : "team.manageBilling",
fallbackRoles: [MembershipRole.ADMIN, MembershipRole.OWNER],
});
if (!hasManageBillingPermission) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
}
}
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
const creditService = new CreditService();
const credits = await creditService.getAllCredits({ userId: ctx.user.id, teamId });
return { credits };
};