Files
website-secure/app/api/planning-history/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

28 lines
928 B
TypeScript

import { NextResponse } from "next/server";
import { getDb } from "@/lib/db";
export async function GET() {
try {
const sql = getDb();
const rows = await sql(
`SELECT ph.*,
COUNT(phi.id) AS item_count,
COALESCE(SUM(phi.quantity_needed), 0) AS total_quantity,
COUNT(CASE WHEN phi.shortage > 0 THEN 1 END) AS shortage_count,
(SELECT string_agg(DISTINCT sp.po_number, ', ' ORDER BY sp.po_number)
FROM supplier_pos sp WHERE sp.planning_id = ph.id) AS linked_po_numbers
FROM planning_history ph
LEFT JOIN planning_history_items phi ON phi.planning_id = ph.id
GROUP BY ph.id
ORDER BY ph.created_at DESC`
);
return NextResponse.json(rows);
} catch (error) {
console.error("Error fetching planning history:", error);
return NextResponse.json(
{ error: "Failed to fetch planning history" },
{ status: 500 }
);
}
}