This commit is contained in:
root
2025-12-20 22:05:21 +01:00
parent e1a0966dee
commit f2c3b04a88
10 changed files with 1134 additions and 28 deletions

View File

@@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from 'next/server'
import pool from '@/lib/db'
// GET /api/sales/list - Get all sales with related data
export async function GET(request: NextRequest) {
try {
const [rows] = await pool.execute(
`SELECT
s.id,
s.drop_id,
s.buyer_id,
s.size,
s.payment_id,
s.created_at,
d.item as drop_item,
d.unit as drop_unit,
d.ppu as drop_ppu,
b.username as buyer_username,
b.email as buyer_email
FROM sales s
LEFT JOIN drops d ON s.drop_id = d.id
LEFT JOIN buyers b ON s.buyer_id = b.id
ORDER BY s.created_at DESC`
)
return NextResponse.json(rows)
} catch (error) {
console.error('Error fetching sales:', error)
return NextResponse.json(
{ error: 'Failed to fetch sales' },
{ status: 500 }
)
}
}