nfel 895afc44af
main: add many things to app :)
Signed-off-by: nfel <nfilsaraee@gmail.com>
2025-12-30 01:30:31 +03:30

47 lines
1.1 KiB
TypeScript

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 }
);
}
}