import { NextRequest, NextResponse } from 'next/server'; import { getDatabase } from '@/lib/db'; export async function PATCH( request: NextRequest, { params }: { params: Promise<{ id: string }> } ) { try { const { id } = await params; const purchaseId = parseInt(id); if (isNaN(purchaseId)) { return NextResponse.json( { error: 'Invalid purchase ID' }, { status: 400 } ); } const db = getDatabase(); // Update purchase status to rejected const result = db.prepare(` UPDATE purchases SET approvalStatus = 'rejected' WHERE id = ? `).run(purchaseId); if (result.changes === 0) { return NextResponse.json( { error: 'Purchase not found' }, { status: 404 } ); } return NextResponse.json({ success: true, message: 'Purchase rejected successfully' }); } catch (error: any) { console.error('Error rejecting purchase:', error); return NextResponse.json( { error: error.message || 'Failed to reject purchase' }, { status: 500 } ); } }