admin docs: only list objects that actually exist (drop dead/phantom rows)

Filter the documents list to objects that exist in storage, so stray keys (a
template pdf_minio_path, or a phantom mcs150 esign_records row on a UCR order
from the shared remediation pipeline) no longer surface as dead rows. The UI
drops the now-unreachable 'not generated yet' branch.
This commit is contained in:
justin 2026-06-16 02:37:33 -05:00
parent c8e0065729
commit 8e1e2f16bf
2 changed files with 10 additions and 8 deletions

View file

@ -704,9 +704,11 @@ router.get("/api/v1/admin/compliance-orders/:order_number/documents", requireAdm
const exists = await pool.query("SELECT 1 FROM compliance_orders WHERE order_number = $1", [req.params.order_number]);
if (exists.rows.length === 0) { res.status(404).json({ error: "Order not found." }); return; }
const docs = await collectOrderDocuments(req.params.order_number);
// Verify each object actually exists in storage so the UI can disable dead
// links (a key can be recorded in the DB before the object is uploaded, e.g.
// a prepared-filing path written for an order whose prep never completed).
// Verify each object actually exists in storage. A key can be recorded in
// the DB before (or without) the object ever being uploaded -- e.g. a
// template pdf_minio_path, or a stray esign_records row from the shared
// remediation pipeline. We DROP non-existent objects so the UI only ever
// lists documents you can actually open; the empty state explains the rest.
const checked = await Promise.all(docs.map(async (d) => {
let present = false;
try {
@ -721,7 +723,8 @@ router.get("/api/v1/admin/compliance-orders/:order_number/documents", requireAdm
} catch { /* treat as missing */ }
return { ...d, exists: present };
}));
res.json({ order_number: req.params.order_number, documents: checked });
const available = checked.filter((d) => d.exists);
res.json({ order_number: req.params.order_number, documents: available });
} catch (err) {
console.error("[admin/compliance-orders/documents] Error:", err);
res.status(500).json({ error: "Could not list documents." });