38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getDb } from "@/lib/db";
|
|
|
|
export async function PUT(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ productId: string; itemId: string }> }
|
|
) {
|
|
const sql = getDb();
|
|
const { itemId } = await params;
|
|
const body = await request.json();
|
|
const { component_id, quantity, reference_designator, notes } = body;
|
|
|
|
const rows = await sql(
|
|
`UPDATE bom_items SET
|
|
component_id = $1, quantity = $2, reference_designator = $3, notes = $4
|
|
WHERE id = $5
|
|
RETURNING *`,
|
|
[component_id, quantity || 1, reference_designator || null, notes || null, Number(itemId)]
|
|
);
|
|
|
|
if (rows.length === 0) {
|
|
return NextResponse.json({ error: "BOM item not found" }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json(rows[0]);
|
|
}
|
|
|
|
export async function DELETE(
|
|
_request: NextRequest,
|
|
{ params }: { params: Promise<{ productId: string; itemId: string }> }
|
|
) {
|
|
const sql = getDb();
|
|
const { itemId } = await params;
|
|
|
|
await sql(`DELETE FROM bom_items WHERE id = $1`, [Number(itemId)]);
|
|
return NextResponse.json({ success: true });
|
|
}
|