dow-prod-tracker/src
DJP 47a65d6498 Keep Deliverable.status in sync with stage state
Root cause of the mismatch: Deliverable.status is a denormalised
column that was only written at create-time (default NOT_STARTED)
and never refreshed when stages moved. The Projects board read it
live and showed "Not Started" while the pipeline ring + dominant-
stage view correctly showed "at Client Feedback (6/11 stages
complete)".

Fix in two parts:

1. New deliverable-status-service with:
   - computeDeliverableStatus(stageStatuses[]) — pure function with
     the summary rule:
        all stages terminal              → APPROVED
        any IN_REVIEW                    → IN_REVIEW
        any IN_PROGRESS/CHANGES_REQUESTED → IN_PROGRESS
        else                             → NOT_STARTED
     ON_HOLD is producer-managed and never overwritten.
   - recomputeDeliverableStatus(deliverableId, txClient?) —
     executes the rule + writes if different. Accepts an optional
     Prisma tx client so callers can run inside their own
     transaction.

2. Wired into every stage-write path:
   - stage-service.updateStageStatus (single-stage transitions)
   - stage-service bulk transaction (bulkUpdateStages) — dedups
     touched deliverable IDs so we don't recompute twice.
   - stage-transition-service forward + rework (board drag) —
     inline inside the same $transaction so the board bucket is
     correct on the next refetch.

3. Backfill script scripts/recompute-deliverable-statuses.ts —
   one-off sweep to fix existing stale rows:
     npx tsx scripts/recompute-deliverable-statuses.ts
   Run once after deploy.
2026-04-21 19:55:39 -04:00
..
app Project Owner is now a User, not freeform text 2026-04-21 19:43:14 -04:00
components Breadcrumbs show names + OMG number instead of raw cuids 2026-04-21 19:44:45 -04:00
hooks Assign + book hours in one shot from the stage card 2026-04-21 15:31:20 -04:00
lib Keep Deliverable.status in sync with stage state 2026-04-21 19:55:39 -04:00
stores feat: add pipeline stage resolver and organization access control 2026-03-14 22:43:43 -05:00
types Phase 2: per-client-team visibility enforcement 2026-04-20 18:50:00 -04:00
instrumentation.ts automation rules added to settings 2026-03-17 23:07:44 -05:00
middleware.ts Smoke-test fixes: routing collision + XLSX parser + defaults 2026-04-20 19:47:22 -04:00