Files
calendar/packages/trpc/server/routers/viewer/teams/skipTeamTrials.handler.ts
Benny JooandGitHub ff38d6c7db refactor: Remove circular deps between @calcom/lib and @calcom/features [1] (#24399)
* add eslint config

* migrate autoLock to features

* migrate teamService to features

* migrate userCreationService

* migrate insights services to features

* migrate ProfileRepository

* update imports

* migrate filter segmen tests

* migrate filter segment repository

* migrate getBusyTimes

* migrate getLocaleFromRequest

* refactor csvUtils

* make filename clearer

* migrate getLuckyUser integration test

* migrate autoLock test to features

* wip

* refactors

* migrate useBookerUrl

* migrate more

* wip

* Migrate eventTypeRepository

* membership repository

* update imports

* update imports

* migrate

* move organization repository

* update imports

* update imports

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix tests

* fix type checks

* fix

* fix

* migrate

* update imports

* fix tests

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix
2025-10-13 12:01:02 -03:00

56 lines
1.7 KiB
TypeScript

import { InternalTeamBilling } from "@calcom/ee/billing/teams/internal-team-billing";
import { IS_SELF_HOSTED } from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import { MembershipRepository } from "@calcom/features/membership/repositories/MembershipRepository";
import { prisma } from "@calcom/prisma";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
import type { TSkipTeamTrialsInputSchema } from "./skipTeamTrials.schema";
const log = logger.getSubLogger({ prefix: ["skipTeamTrials"] });
type SkipTeamTrialsOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TSkipTeamTrialsInputSchema;
};
export const skipTeamTrialsHandler = async ({ ctx }: SkipTeamTrialsOptions) => {
// If self-hosted, no need to skip trials as they're already handled differently
if (IS_SELF_HOSTED) return { success: true };
try {
await prisma.user.update({
where: {
id: ctx.user.id,
},
data: {
trialEndsAt: null,
},
});
const ownedTeams = await MembershipRepository.findAllAcceptedTeamMemberships(ctx.user.id, {
role: "OWNER",
});
for (const team of ownedTeams) {
const teamBillingService = new InternalTeamBilling(team);
const subscriptionStatus = await teamBillingService.getSubscriptionStatus();
if (subscriptionStatus === "trialing") {
await teamBillingService.endTrial();
log.info(`Ended trial for team ${team.id}`);
}
}
return { success: true };
} catch (error) {
log.error("Error skipping team trials", error);
return { success: false, error: "Failed to skip team trials" };
}
};
export default skipTeamTrialsHandler;