Auto-save intake data to server after every step

Intake data now persists to DB after each step completion (non-blocking).
If browser crashes, data is recoverable from compliance_orders.intake_data.

Partial saves (_partial: true) only update intake_data without changing
payment_status or marking intake_data_validated. Final submit still
triggers the full validation + worker dispatch flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-30 16:01:20 -05:00
parent beb23d777e
commit c40dfb552e
2 changed files with 43 additions and 10 deletions

View file

@ -1758,7 +1758,7 @@ router.get("/api/v1/compliance-orders/my-orders", async (req, res) => {
*/
router.put("/api/v1/compliance-orders/:id/intake", async (req, res) => {
const id = req.params.id;
const { intake_data, entity, officers } = req.body ?? {};
const { intake_data, entity, officers, _partial } = req.body ?? {};
if (!intake_data) {
res.status(400).json({ error: "intake_data required" });
@ -1798,15 +1798,23 @@ router.put("/api/v1/compliance-orders/:id/intake", async (req, res) => {
}
// 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,
telecom_entity_id = COALESCE($3, telecom_entity_id)
WHERE order_number = $2`,
[JSON.stringify(merged), id, telecomEntityId],
);
// Partial saves (auto-save between steps) only update intake_data, not status
if (_partial) {
await pool.query(
`UPDATE compliance_orders SET intake_data = $1 WHERE order_number = $2`,
[JSON.stringify(merged), id],
);
} else {
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,
telecom_entity_id = COALESCE($3, telecom_entity_id)
WHERE order_number = $2`,
[JSON.stringify(merged), id, telecomEntityId],
);
}
// If entity data was provided, update the telecom_entity too
if (entity && entity.frn) {