Skip to content

Commit cff4de6

Browse files
fix: fetch all credit fields directly from supabase in billing API
Made-with: Cursor
1 parent b8bb24a commit cff4de6

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

src/app/api/billing/credits/route.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ export async function GET() {
99

1010
const { data: orgData } = await supabaseAdmin
1111
.from('organizations')
12-
.select('credit_balance_eur')
12+
.select('credit_balance_eur, auto_topup_enabled, auto_topup_amount_eur, auto_topup_threshold_eur, auto_topup_failed')
1313
.eq('id', org.id)
1414
.single()
1515

16-
const balance = orgData ? Number(orgData.credit_balance_eur) : 0
17-
1816
const { data: transactions } = await supabaseAdmin
1917
.from('credit_transactions')
2018
.select('id, type, amount_eur, balance_after_eur, model, description, created_at')
@@ -23,11 +21,11 @@ export async function GET() {
2321
.limit(20)
2422

2523
return NextResponse.json({
26-
credit_balance_eur: balance,
27-
auto_topup_enabled: org.auto_topup_enabled,
28-
auto_topup_amount_eur: Number(org.auto_topup_amount_eur),
29-
auto_topup_threshold_eur: Number(org.auto_topup_threshold_eur),
30-
auto_topup_failed: org.auto_topup_failed,
24+
credit_balance_eur: orgData ? Number(orgData.credit_balance_eur) : 0,
25+
auto_topup_enabled: orgData?.auto_topup_enabled ?? true,
26+
auto_topup_amount_eur: orgData ? Number(orgData.auto_topup_amount_eur) : 20,
27+
auto_topup_threshold_eur: orgData ? Number(orgData.auto_topup_threshold_eur) : 2,
28+
auto_topup_failed: orgData?.auto_topup_failed ?? false,
3129
recent_transactions: transactions ?? [],
3230
})
3331
}

0 commit comments

Comments
 (0)