Link telecom_entity_id by FRN on intake save, fix batch siblings
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3dce721120
commit
d6c513bca5
1 changed files with 22 additions and 5 deletions
|
|
@ -1565,14 +1565,30 @@ router.put("/api/v1/compliance-orders/:id/intake", async (req, res) => {
|
|||
: order.intake_data) || {};
|
||||
const merged = { ...oldIntake, ...intake_data };
|
||||
|
||||
// Update the order with merged intake data
|
||||
// Look up telecom_entity_id from FRN
|
||||
let telecomEntityId: number | null = null;
|
||||
const frn = entity?.frn || merged.frn;
|
||||
if (frn) {
|
||||
try {
|
||||
const teResult = await pool.query(
|
||||
`SELECT id FROM telecom_entities WHERE frn = $1 LIMIT 1`,
|
||||
[frn],
|
||||
);
|
||||
if (teResult.rows.length > 0) {
|
||||
telecomEntityId = (teResult.rows[0] as any).id;
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
// Update the order with merged intake data + entity link
|
||||
await pool.query(
|
||||
`UPDATE compliance_orders
|
||||
SET intake_data = $1,
|
||||
payment_status = CASE WHEN payment_status = 'pending_intake' THEN 'paid' ELSE payment_status END,
|
||||
intake_data_validated = TRUE
|
||||
intake_data_validated = TRUE,
|
||||
telecom_entity_id = COALESCE($3, telecom_entity_id)
|
||||
WHERE order_number = $2`,
|
||||
[JSON.stringify(merged), id],
|
||||
[JSON.stringify(merged), id, telecomEntityId],
|
||||
);
|
||||
|
||||
// If entity data was provided, update the telecom_entity too
|
||||
|
|
@ -1636,9 +1652,10 @@ router.put("/api/v1/compliance-orders/:id/intake", async (req, res) => {
|
|||
await pool.query(
|
||||
`UPDATE compliance_orders
|
||||
SET intake_data = jsonb_set(COALESCE(intake_data::jsonb, '{}'::jsonb), '{entity_filled}', 'true'::jsonb),
|
||||
payment_status = 'paid'
|
||||
payment_status = 'paid',
|
||||
telecom_entity_id = COALESCE($2, telecom_entity_id)
|
||||
WHERE order_number = $1 AND payment_status = 'pending_intake'`,
|
||||
[po.order_number],
|
||||
[po.order_number, telecomEntityId],
|
||||
);
|
||||
// Dispatch worker
|
||||
setImmediate(async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue