feat: disallow double lifetime buys

This commit is contained in:
2026-03-24 22:01:05 +04:00
parent 1a00d49be2
commit bea1a91eb9
3 changed files with 21 additions and 7 deletions
+5 -3
View File
@@ -60,10 +60,12 @@ export const routes = new Elysia()
const { plan, months, coin } = body;
// Validate plan
// Validate plan — block duplicate lifetime
if (plan === "lifetime") {
const [acc] = await sql`SELECT plan FROM accounts WHERE id = ${accountId}`;
if (acc.plan === "lifetime") { set.status = 400; return { error: "Already on lifetime plan" }; }
const [acc] = await sql`SELECT plan, plan_stack FROM accounts WHERE id = ${accountId}`;
const stack = typeof acc.plan_stack === "string" ? JSON.parse(acc.plan_stack) : (acc.plan_stack || []);
const hasLifetime = acc.plan === "lifetime" || stack.some((s: any) => s.plan === "lifetime");
if (hasLifetime) { set.status = 400; return { error: "You already have a lifetime plan" }; }
}
// Validate coin