main: add many things to app :)

Signed-off-by: nfel <nfilsaraee@gmail.com>
This commit is contained in:
2025-12-30 01:30:31 +03:30
parent 91c149e92e
commit 895afc44af
26 changed files with 2180 additions and 249 deletions
+46
View File
@@ -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 }
);
}
}
+46
View File
@@ -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 }
);
}
}