main: add many things to app :)
Signed-off-by: nfel <nfilsaraee@gmail.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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 approved
|
||||
const result = db.prepare(`
|
||||
UPDATE purchases
|
||||
SET approvalStatus = 'approved'
|
||||
WHERE id = ?
|
||||
`).run(purchaseId);
|
||||
|
||||
if (result.changes === 0) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Purchase not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: 'Purchase approved successfully'
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('Error approving purchase:', error);
|
||||
return NextResponse.json(
|
||||
{ error: error.message || 'Failed to approve purchase' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user