Skip to content

Commit

Permalink
chore(website): add new plan type
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Oct 27, 2024
1 parent eba7387 commit 8451bf3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
7 changes: 6 additions & 1 deletion apps/website/app/drizzle/schema.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export const ProductTypes = z.enum(productTypes.enumValues);

export type TProductTypes = z.infer<typeof ProductTypes>;

export const planTypes = pgEnum("plan_type", ["monthly", "yearly", "lifetime"]);
export const planTypes = pgEnum("plan_type", [
"free",
"monthly",
"yearly",
"lifetime",
]);

export const PlanTypes = z.enum(planTypes.enumValues);

Expand Down
24 changes: 9 additions & 15 deletions apps/website/app/lib/config.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export const OAUTH_CALLBACK_URL = `${serverVariables.FRONTEND_URL}/callback`;

export const pricesSchema = z.array(
z.object({
type: z.string(),
type: z.nativeEnum(ProductTypes.Values),
prices: z.array(
z.object({
name: z.string(),
linkToGithub: z.boolean().optional(),
priceId: z.string().optional(),
amount: z.number().optional(),
trial: z.number().optional(),
amount: z.number().optional(),
priceId: z.string().optional(),
linkToGithub: z.boolean().optional(),
name: z.nativeEnum(PlanTypes.Values),
}),
),
}),
Expand All @@ -67,16 +67,10 @@ export const prices = pricesSchema.parse(
);

export const getProductAndPlanTypeByPriceId = (priceId: string) => {
for (const product of prices) {
for (const price of product.prices) {
if (price.priceId === priceId) {
return {
productType: ProductTypes.parse(product.type),
planType: PlanTypes.parse(price.name),
};
}
}
}
for (const product of prices)
for (const price of product.prices)
if (price.priceId === priceId)
return { productType: product.type, planType: price.name };
throw new Error("Price ID not found");
};

Expand Down

0 comments on commit 8451bf3

Please sign in to comment.