Files
website-secure/app/api/bom/[productId]/[itemId]/route.ts
T
pm 9c14a19a87
DevSecOps Enterprise Pipeline / security-gate-and-deploy (push) Failing after 41s
chore: upload parte 1 - logica
2026-06-01 15:35:53 +01:00

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