mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* 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]>
42 lines
1.4 KiB
TypeScript
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 };
|
|
};
|