feat: whyrating - initial project from turbostarter boilerplate

This commit is contained in:
Alejandro Gutiérrez
2026-02-04 01:54:52 +01:00
commit 5cdc07cd39
1618 changed files with 338230 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import { HttpStatusCode } from "@turbostarter/shared/constants";
import { logger } from "@turbostarter/shared/logger";
import { HttpException } from "@turbostarter/shared/utils";
import { config } from "../../config";
import { getCustomerByCustomerId, updateCustomer } from "../../lib/customer";
import { polar } from "./client";
import { toBillingStatus } from "./mappers/to-billing-status";
export const subscriptionStatusChangeHandler = async ({
id,
}: {
id: string;
}) => {
const subscription = await polar().subscriptions.get({ id });
const customer = await getCustomerByCustomerId(subscription.customerId);
if (!customer) {
throw new HttpException(HttpStatusCode.NOT_FOUND, {
code: "billing:error.customerNotFound",
});
}
const priceId = subscription.productId;
const plan = config.plans.find((p) => p.prices.find((x) => x.id === priceId));
await updateCustomer(customer.userId, {
status: toBillingStatus(subscription.status),
...(plan && { plan: plan.id }),
});
logger.info(
`✅ Subscription status changed for user ${customer.userId} to ${subscription.status}`,
);
};