rc 1.0
This commit is contained in:
@@ -1,13 +1,37 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import pool from '@/lib/db'
|
||||
|
||||
// GET /api/buyers - Get all buyers
|
||||
// GET /api/buyers - Get all buyers with referral counts
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const [rows] = await pool.execute(
|
||||
'SELECT id, username, email, created_at FROM buyers ORDER BY created_at DESC'
|
||||
`SELECT
|
||||
b.id,
|
||||
b.username,
|
||||
b.email,
|
||||
b.created_at,
|
||||
COALESCE(ref_counts.referral_count, 0) as referral_count
|
||||
FROM buyers b
|
||||
LEFT JOIN (
|
||||
SELECT referrer, COUNT(*) as referral_count
|
||||
FROM referrals
|
||||
GROUP BY referrer
|
||||
) ref_counts ON b.id = ref_counts.referrer
|
||||
ORDER BY b.created_at DESC`
|
||||
)
|
||||
return NextResponse.json(rows)
|
||||
|
||||
// Add access status for each buyer
|
||||
const buyersWithAccess = (rows as any[]).map((buyer: any) => {
|
||||
const referralCount = parseInt(buyer.referral_count) || 0
|
||||
return {
|
||||
...buyer,
|
||||
referral_count: referralCount,
|
||||
hasWholesaleAccess: referralCount >= 3,
|
||||
hasInnerCircleAccess: referralCount >= 10
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json(buyersWithAccess)
|
||||
} catch (error) {
|
||||
console.error('Error fetching buyers:', error)
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user