fix: sql schemas names on dashboard and tenants API
Build and Deploy (Gitea Actions) / build-and-deploy (push) Successful in 2m34s Details

This commit is contained in:
Sidney 2026-06-07 21:26:29 -03:00
parent 793135850b
commit d2f0670ce7
2 changed files with 9 additions and 9 deletions

View File

@ -15,9 +15,9 @@ export async function GET() {
// Total MRR // Total MRR
const mrrRes = await query(` const mrrRes = await query(`
SELECT COALESCE(SUM(p.price), 0) as mrr SELECT COALESCE(SUM(p.price_monthly), 0) as mrr
FROM tenants t FROM tenants t
JOIN plans p ON t.active_plan_id = p.id JOIN plans p ON t.plan_id = p.id
WHERE t.subscription_status = 'active' WHERE t.subscription_status = 'active'
`); `);
const mrr = mrrRes.rows[0].mrr; const mrr = mrrRes.rows[0].mrr;
@ -26,7 +26,7 @@ export async function GET() {
const plansRes = await query(` const plansRes = await query(`
SELECT p.name, COUNT(t.id) as count SELECT p.name, COUNT(t.id) as count
FROM plans p FROM plans p
LEFT JOIN tenants t ON t.active_plan_id = p.id AND t.subscription_status = 'active' LEFT JOIN tenants t ON t.plan_id = p.id AND t.subscription_status = 'active'
GROUP BY p.name GROUP BY p.name
ORDER BY count DESC ORDER BY count DESC
`); `);
@ -34,9 +34,9 @@ export async function GET() {
// Recent tenants // Recent tenants
const recentRes = await query(` const recentRes = await query(`
SELECT t.id, t.name, COALESCE(p.name, 'N/A') as plan, t.subscription_status as status, SELECT t.id, t.name, COALESCE(p.name, 'N/A') as plan, t.subscription_status as status,
COALESCE(p.price, 0) as mrr, TO_CHAR(t.created_at, 'YYYY-MM-DD') as date COALESCE(p.price_monthly, 0) as mrr, TO_CHAR(t.created_at, 'YYYY-MM-DD') as date
FROM tenants t FROM tenants t
LEFT JOIN plans p ON t.active_plan_id = p.id LEFT JOIN plans p ON t.plan_id = p.id
ORDER BY t.created_at DESC ORDER BY t.created_at DESC
LIMIT 5 LIMIT 5
`); `);

View File

@ -8,11 +8,11 @@ export async function GET(req: NextRequest) {
COALESCE(p.name, 'Starter') as plan, COALESCE(p.name, 'Starter') as plan,
t.subscription_status as status, t.subscription_status as status,
t.email, t.phone, t.email, t.phone,
COALESCE(p.price, 0) as mrr, COALESCE(p.price_monthly, 0) as mrr,
TO_CHAR(t.created_at, 'YYYY-MM-DD') as "createdAt", TO_CHAR(t.created_at, 'YYYY-MM-DD') as "createdAt",
TO_CHAR(t.subscription_ends_at, 'YYYY-MM-DD') as "trialEnds" TO_CHAR(t.subscription_ends_at, 'YYYY-MM-DD') as "trialEnds"
FROM tenants t FROM tenants t
LEFT JOIN plans p ON t.active_plan_id = p.id LEFT JOIN plans p ON t.plan_id = p.id
ORDER BY t.created_at DESC ORDER BY t.created_at DESC
`); `);
@ -39,7 +39,7 @@ export async function POST(req: NextRequest) {
const planId = planRes.rows.length > 0 ? planRes.rows[0].id : null; const planId = planRes.rows.length > 0 ? planRes.rows[0].id : null;
const res = await query( const res = await query(
`INSERT INTO tenants (name, slug, email, phone, active_plan_id, subscription_status, subscription_ends_at) `INSERT INTO tenants (name, slug, email, phone, plan_id, subscription_status, subscription_ends_at)
VALUES ($1, $2, $3, $4, $5, $6, NOW() + INTERVAL '30 days') RETURNING *`, VALUES ($1, $2, $3, $4, $5, $6, NOW() + INTERVAL '30 days') RETURNING *`,
[name, slug, email, phone, planId, status || 'trial'] [name, slug, email, phone, planId, status || 'trial']
); );
@ -71,7 +71,7 @@ export async function PUT(req: NextRequest) {
const res = await query( const res = await query(
`UPDATE tenants `UPDATE tenants
SET name = $1, slug = $2, email = $3, phone = $4, active_plan_id = $5, subscription_status = $6, updated_at = NOW() SET name = $1, slug = $2, email = $3, phone = $4, plan_id = $5, subscription_status = $6, updated_at = NOW()
WHERE id = $7 RETURNING *`, WHERE id = $7 RETURNING *`,
[name, slug, email, phone, planId, status, id] [name, slug, email, phone, planId, status, id]
); );