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:
parent
c8e0065729
commit
8e1e2f16bf
2 changed files with 10 additions and 8 deletions
|
|
@ -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." });
|
||||
|
|
|
|||
|
|
@ -401,13 +401,12 @@
|
|||
box.innerHTML = documents.map((d) => {
|
||||
const u = API + "/api/v1/admin/compliance-orders/" + encodeURIComponent(orderNumber)
|
||||
+ "/document?key=" + encodeURIComponent(d.key) + "&token=" + tok;
|
||||
const action = (d.exists === false)
|
||||
? `<span class="small" style="color:#9ca3af;">not generated yet</span>`
|
||||
: `<a href="${u}" target="_blank" rel="noopener" class="btn btn-blue btn-sm" style="text-decoration:none;">View</a>`;
|
||||
return `<div class="svc-row"><div class="svc-left">
|
||||
<span style="font-size:13px;">${esc(d.label)}</span>
|
||||
<span class="small">${esc(d.key.split("/").pop())}</span>
|
||||
</div><div class="svc-right">${action}</div></div>`;
|
||||
</div><div class="svc-right">
|
||||
<a href="${u}" target="_blank" rel="noopener" class="btn btn-blue btn-sm" style="text-decoration:none;">View</a>
|
||||
</div></div>`;
|
||||
}).join("");
|
||||
} catch (e) {
|
||||
box.innerHTML = `<div style="color:#b91c1c;font-size:12px;">Could not load documents: ${esc(e.message)}</div>`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue