update: lifetime discounts based on spent

This commit is contained in:
2026-03-22 06:11:49 +04:00
parent b014cbf98a
commit a1d37c6215
3 changed files with 26 additions and 3 deletions
+4 -1
View File
@@ -273,6 +273,9 @@ export const dashboard = new Elysia()
const [acc] = await sql`SELECT plan, plan_expires_at FROM accounts WHERE id = ${resolved.accountId}`;
if (acc.plan === "lifetime") return redirect("/dashboard/settings");
// Total spent on paid invoices (for lifetime discount)
const [{ total_spent }] = await sql`SELECT COALESCE(SUM(amount_usd), 0)::numeric as total_spent FROM payments WHERE account_id = ${resolved.accountId} AND status = 'paid'`;
// Fetch coins server-side for no-JS rendering
const payApi = process.env.PAY_API || "https://pay.pingql.com";
let coins: any[] = [];
@@ -282,7 +285,7 @@ export const dashboard = new Elysia()
coins = data.coins || [];
} catch {}
return html("checkout", { nav: "settings", account: acc, payApi, invoiceId: null, coins, invoice: null });
return html("checkout", { nav: "settings", account: acc, payApi, invoiceId: null, coins, invoice: null, totalSpent: Number(total_spent) });
})
// Existing invoice by ID — SSR the payment status