notification + admin panel
This commit is contained in:
51
app/api/sales/drop/[dropId]/route.ts
Normal file
51
app/api/sales/drop/[dropId]/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import pool from '@/lib/db'
|
||||
|
||||
// GET /api/sales/drop/[dropId] - Get all sales for a specific drop
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { dropId: string } }
|
||||
) {
|
||||
try {
|
||||
const dropId = parseInt(params.dropId, 10)
|
||||
if (isNaN(dropId)) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid drop ID' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
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,
|
||||
bd.fullname as buyer_fullname,
|
||||
bd.address as buyer_address,
|
||||
bd.phone as buyer_phone
|
||||
FROM sales s
|
||||
LEFT JOIN drops d ON s.drop_id = d.id
|
||||
LEFT JOIN buyers b ON s.buyer_id = b.id
|
||||
LEFT JOIN buyer_data bd ON s.buyer_data_id = bd.id
|
||||
WHERE s.drop_id = ?
|
||||
ORDER BY s.created_at DESC`,
|
||||
[dropId]
|
||||
)
|
||||
return NextResponse.json(rows)
|
||||
} catch (error) {
|
||||
console.error('Error fetching sales for drop:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch sales' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user