Skip to main content

Service: plans, history, roster (E10–E13)

:::warning Routed; scheduling/queues are opt-in Every endpoint on this page is implemented and registered as a route in code (packages/core/src/services/{plant-service-tab,maintenance-plan-service,maintenance-history-service,roster-service}.ts, handlers plant-service.ts, maintenance-plans.ts, maintenance-history.ts, service-roster.ts), in the route-area stack cse-http-be-<stage>-api-service (families plant-service, maintenance-plans, maintenance-history, service-roster; Q27). They are routed (the area stack is created by a default cdk synth; the web team observed these routes answering on dev on 2026-10-28). The plan queue, DLQ, worker and hourly scheduler are built in stack cse-http-be-<stage>-service, which exists only with -c busEnabled=true. Without it scheduled plans never fire and :run-now answers 503 DEPENDENCY_UNAVAILABLE (no PLAN_CYCLES_QUEUE_URL). With it, the hourly tick still stays DISABLED unless -c servicePlansEnabled=true (run-now works either way). Nothing here has been executed against any stage; every example is an illustrative example, derived from the schema/handler code. The machine-readable contract is docs/openapi.yaml. :::

Common headers, pagination, non-disclosure and error rules are the same as work orders. Customer audience gets 403 on plans and roster.

E10 — GET /v1/plants/{plantId}/service (plant Service tab)​

AuthZ service ≥ VIEW @plant. Query openLimit 1–20 (default 15 on the first page, 10 with a cursor — lazy loading), cursor (open list: send the previous openWorkOrders.nextCursor; such a page skips the recent-history read and returns recentHistory: []). Returns open orders (newest first), up to 10 recent closed orders, device warranties and service contracts. ADR 0012: warranties is always [] (device warranty data belongs to TCP).

// illustrative example, derived from the schema/handler code
{ "plantId": "01J…", "counts": { "open": 2, "pastTarget": 0 },
"openWorkOrders": { "items": [], "nextCursor": null },
"recentHistory": [],
"warranties": [],
"contracts": [{ "contractId": "01J…", "kind": "OM_CONTRACT", "component": "PLANT", "provider": "Crown Solar", "tier": "Gold", "status": "ACTIVE", "renewsOn": "2026-12-31", "version": 1 }],
"viewer": { "audience": "INTERNAL", "capabilities": ["workOrder.create", "contract.manage"] } }

recentHistory is drawn from the ~30 newest-created orders of the plant, so it is not a complete history — use E12 for that.

Lifecycle v2 (ADR 0023; built, not deployed). openWorkOrders holds the v2 open set, so COMPLETED and VERIFIED orders stay in it until the Business closes them. recentHistory lists CLOSED and CANCELLED orders. counts.pastTarget never counts COMPLETED or VERIFIED orders. See the status model.

Rows carry operator {orgId, name?} (the responsible Business, WO-6).

Installer tier (WO-4, ADR 0019). A caller who reaches the plant through an operator membership below service MANAGE, with no platform membership, sees only the orders assigned to them in openWorkOrders and recentHistory. Their counts are computed over the open orders on this page, never the plant's totals. Deployed on dev (2026-11-05).

Contracts: PUT /v1/plants/{plantId}/service/contracts/{contractId} — service ≥ MANAGE @plant; create with a client-generated ULID and If-None-Match: * (201) or replace with If-Match (200); ≤ 50 per plant. DELETE …/contracts/{contractId} — MANAGE, If-Match, 204. Errors 403, 404, 409 VERSION_CONFLICT, 422, 428.

E11 — Maintenance plans​

OperationAuthZIdemNotes
GET /v1/orgs/{orgId}/maintenance-plans?status=&teamId=service ≥ VIEW @org—paginated plan cards incl. openCount
POST /v1/orgs/{orgId}/maintenance-plansservice ≥ MANAGE @orgR201 plan, code MP-NNN
GET …/{planId}VIEW—plan + nextDueOn, recurrenceLabel, scopeSummary
PATCH …/{planId}MANAGE—If-Match; ≥ 1 field, null clears; recomputes nextDispatchAt
POST …/{planId}:pause / :resumeMANAGEOIf-Match; 409 INVALID_STATE if already in that state or ENDED
POST …/{planId}:run-nowMANAGER202 {runId, cycleKey, plantCount, status: "QUEUED", links.self}; 6 per hour per plan (429); 409 INVALID_STATE if PAUSED/ENDED; 503 DEPENDENCY_UNAVAILABLE before any run is written — when the stage was deployed without busEnabled (no PLAN_CYCLES_QUEUE_URL) or the enqueue fails
GET …/{planId}/runs/{runId}VIEW—run record (poll after run-now)
POST /v1/orgs/{orgId}/maintenance-plans:preview-scopeMANAGE—{scopeRule} → {plantCount, sample: [{plantId, name, code}] ≤ 20}. Served by route POST /v1/orgs/{orgId}/{collection} (OrgCollectionAction, CR-2); the client still calls the colon URL

Plan body (CreatePlanInput): title 3–120, note? ≤ 2000, autoCreate (default true), recurrence, scopeRule, startOn, endOn? (≥ startOn), leadDays 0–90 (default 7), priority (default LOW), workType (default PREVENTIVE_MAINTENANCE), tasks[] ≤ 30 × 200 chars, teamId?, defaultTechnicianSub?. Status is stored ACTIVE/PAUSED; ENDED is derived when endOn is in the past.

Plan view (list items and every single-plan response) is the stored plan plus recurrenceLabel, scopeSummary, nextDueOn?, openCount and, since 2026-11-17, teamName?: the name of teamId's team, read with one batched read per page. It is absent when the plan has no team or the team was deleted.

Recurrence: {intervalMonths: 1–24, anchor} where anchor is {kind: "DAY_OF_MONTH", dayOfMonth: 1–28, firstDueOn} or {kind: "COMMISSIONING_ANNIVERSARY"} (then intervalMonths must be 3, 6 or 12). Orders are dispatched leadDays before each due date.

Scope rule (evaluated fresh at every run): tagIds[], plantTypes[], capacityMinKwp, capacityMaxKwp, hasBattery (matches the plant's derived hasBattery: a bound device has a battery on the TCP server, 2026-11-18), cities[]. OR within a field, AND across fields; at least one field; each list 1–10 values (over → 422 LIMIT_EXCEEDED); min ≤ max capacity.

Idempotency of runs: each plant gets at most one order per cycle key (YYYY-MM of the due date; manual runs MANUAL-<YYYY-MM-DD>), so a re-run or duplicate delivery creates nothing new. Generated orders have source: "PLAN" and no SLA target. Plants not managed by an operator org are skipped (PLANT_NOT_ORG_MANAGED).

Validation 422, plus 403, 404, 409 VERSION_CONFLICT, 428.

:::note Admin-web 2026-11-24 Page 1 of GET /maintenance-plans also carries total, every plan of the org. GET /technicians without plantId lists roster profiles only (from the PLATFORM org: every Business's technicians named on closed orders, F4), so it does not cover every assignee that appears in service history. See Admin-web list totals, counts and filter options. :::

E12 — GET /v1/orgs/{orgId}/maintenance-history​

AuthZ service ≥ VIEW @org plus scope filter. Query: from, to (YYYY-MM-DD, org timezone; default last 90 days; span ≤ 366 → else 422), plantId, technicianSub, workType, result, outcome (COMPLETED|CANCELLED, default both) — all repeatable where enums — limit 1–50 (default 15 on the first page, 10 with a cursor — lazy loading), cursor. Sort is fixed: newest closed first.

// illustrative example, derived from the schema/handler code
{ "items": [{ "workOrderId": "01J…", "code": "WO-2026-0472", "closedAt": "…", "outcome": "COMPLETED", "workType": "CLEANING", "result": "RESOLVED", "hoursOnSite": 3.5, "actualCost": { "amount": 18000, "currency": "PKR" } }],
"nextCursor": "…",
"tiles": { "visits": 142, "hoursOnSite": 388.5, "recordedCost": [{ "amount": 2140000, "currency": "PKR" }], "neededReturn": 11, "neededReturnPct": 7.7, "truncated": false, "approximate": true } }
  • tiles appear on the first page only. Unfiltered calls by ALL-scope callers read stream-maintained day rollups (approximate: true) — tiles are approximate and every tile is clamped at 0 on the summed total (a late correction can make a single day negative). Filtered or scoped callers get a capped compute over visible rows (truncated: true when capped).
  • "Needed a return" = result FOLLOW_UP_REQUIRED or REPEAT_VISIT.
  • Customer audience: rows without actualCost/planId; tiles without recordedCost.
  • Shared callers (partner/customer members) must send plantId, or their own technicianSub, or have exactly one shared plant — otherwise 422 SCOPE_TOO_BROAD.

Status: 200, 400, 403, 404 (plantId not visible), 422.

Rows carry operator {orgId, name?} (WO-6). Crown staff read any Business's history by passing that Business's {orgId}, or from their PLATFORM org with ?operatorOrgId=<Business> (422 from any other org). The platform fallback is audited as PLATFORM_ACCESS (WO-8).

Lifecycle v2 (ADR 0023; built, not deployed).

  • A completed visit is a CLOSED order. A COMPLETED or VERIFIED order is still open and not in the history. outcome: "COMPLETED" (the row field and the outcome filter keep that name) means the order was closed after its work was verified. A pre-v2 COMPLETED order that carries closedAt also counts as a completed visit until the backfill rewrites it.
  • Every Business at once (D9). Called with the caller's own PLATFORM org and no operatorOrgId, Crown staff (ACTIVE, scope ALL, service ≥ VIEW there) read the closed orders of every Business from the Crown-wide list entries. Every row is listed (fixed 2026-11-12, not deployed yet; earlier builds dropped the rows of a Business the platform fallback refused). plantId reads that plant's own partition Crown-wide (since 2026-12-01, F2; before, it went through the platform fallback into the plant's operator, which answered 403 for plants of some orgs). Tiles are computed over at most the tiles read budget (truncated: true beyond), never from the day rollups. Orders closed before the backfill created their list entries are missing. See Crown-wide reads.

E12b — GET /v1/orgs/{orgId}/maintenance-history/technicians​

Added 2026-11-24 (console item 4.11): the options for an "Installer / technician" filter on the history screen. Lists everyone named on the org's closed work orders, all time — including people without a roster profile, partner technicians and removed members, which GET /technicians (roster) does not cover.

  • Source. One counter item per technician, ORG#<o>/COUNT#WOHISTTECH#<sub>, updated by the work-order projection on every close and reopen (on the request path, so it works without the stream-router). Ordered by technician id (not by name); sort the options client-side if needed. A technician whose orders were all reopened drops out.
  • Query. limit (1–50; default 15 on the first page, 10 with a cursor), cursor, and operatorOrgId (from the PLATFORM org only). Since 2026-12-01 (F4) the PLATFORM org without operatorOrgId lists every Business's technicians from Crown-wide copies of the counters (ORG#ALL/COUNT#WOHISTTECH#<sub>, also written on close/reopen); before, it answered 400. GET …/technicians (E13) from the PLATFORM org without plantId lists the same people (profile: false, orgId = their Business). Existing closed orders count Crown-wide after a human reruns npm run backfill:wo-console-indexes over every org (no --org).
  • Response 200. { items: [{ technicianSub, displayName?, closedOrders, visits }], nextCursor?, approximate: true }. displayName is the name on the most recently closed order. Send technicianSub back to E12 as the filter.
  • Auth. service ≥ VIEW in the org with an unscoped membership. Scoped and share-based callers get 422 SCOPE_TOO_BROAD (the counters are org-wide and would show technicians outside their scope); keep building their options as before.
  • Backfill. Orders closed before 2026-11-24 are counted only after npm run backfill:wo-console-indexes.

Illustrative example (derived from the handler; no execution captured yet):

{ "items": [{ "technicianSub": "<sub>", "displayName": "<name>", "closedOrders": 12, "visits": 11 }], "nextCursor": "<cursor>", "approximate": true }

E13 — Technicians and teams​

OperationAuthZIdemNotes
GET /v1/orgs/{orgId}/technicians?teamId=&regionTagId=&skill=&active=&plantId=&includePartners=&q=service ≥ VIEW @org—paginated (lazy page sizes 15/10), name order; q = name prefix (works with cursor — the cursor is bound to q); plantId → only eligible Installers; partner technicians only with includePartners=true
GET /v1/orgs/{orgId}/technicians/{sub}VIEW—profile + workload
PUT /v1/orgs/{orgId}/technicians/{sub}service ≥ MANAGE @org—{teamId?, regionTagId?, skills? (≤ 8, unique), active} — full replacement; create with If-None-Match: *, replace with If-Match; 422 if sub is not an ACTIVE member with service ≥ EDIT or an Installer role (WO-5)
GET /v1/orgs/{orgId}/teamsVIEW—paginated (lazy page sizes 15/10)
POST /v1/orgs/{orgId}/teamsMANAGER{name 1–80, description? ≤ 500, regionTagId?, partnerOrgId?} → 201; 409 ALREADY_EXISTS on duplicate name
GET / PATCH /v1/orgs/{orgId}/teams/{teamId}VIEW / MANAGE—PATCH needs If-Match
DELETE /v1/orgs/{orgId}/teams/{teamId}MANAGE—If-Match; 204; 409 INVALID_STATE details {plans, technicians} while referenced

Technician view: {sub, orgId, displayName, teamId?, teamName?, regionTagId?, regionLabel?, skills, active, profile, plantInstaller?, openCount, todayCount, version?, updatedAt?}. openCount/todayCount are eventually consistent counters. teamName and regionLabel (added 2026-11-17) are the team's name and the Region tag's label, read with one batched read per page, so the console no longer reads the team and tag lists to label rows. They are left out when there is no team or region, when the team or tag was deleted, and on partner-org rows (orgId differs from the org being listed), because the caller cannot read another org's teams or tags. Skills: INVERTER, BATTERY, LOGGER, METERING, HV, COMMISSIONING, CLEANING, INSPECTION.

Eligible Installers (WO-5)​

Since 2026-11-04 (ADR 0019; deployed on dev), a person can be assigned to an order on a plant when all of these hold:

  1. They are an ACTIVE member of the plant's operator org (the responsible Business), and the org is not suspended.
  2. Their scope covers the plant. The R-5 assigned-Installer path counts.
  3. On that plant they have service ≥ EDIT, or an Installer role (templateKey: INSTALLER, the seeded R-91 or a copy) at service ≥ VIEW.
  4. If they have a roster profile, it is active.

A roster profile is not required. Profiles only carry team, region and skills.

?plantId= lists exactly these people:

  • members without a profile come back as profile: false, with no version/updatedAt and skills: [];
  • the plant's assigned Installer (R-5) comes first with plantInstaller: true, so the console can preselect them. The backend also uses them as the default: a Business create with technicianSub omitted assigns them when they're eligible; technicianSub: null keeps the order unassigned;
  • a teamId, regionTagId or skill filter can only match profiles, so it drops profile-less members;
  • partner-org technicians appear only with includePartners=true, and they cannot be assigned through E03 or :assign anyway.

The candidate set is capped at 100 people in name order. Assigning anyone else → 422 VALIDATION_FAILED with details {field: technicianSub, reason: INELIGIBLE_ASSIGNEE, cause} (see E03).

From the PLATFORM org (FU-4, 2026-11-10; built, not deployed yet). Crown staff can call GET /v1/orgs/{platformOrgId}/technicians?plantId=<plant> from their own PLATFORM org. It lists the eligible people of the plant's Business, by the rules above, before any order exists. This is what the console's Installer picker uses in the Crown create flow.

  • Access: service ≥ VIEW in that Business through the audited platform fallback (an own membership there is used instead, never bypassed). Otherwise 403 FORBIDDEN.
  • openCount / todayCount are the Business's counters.
  • From an org that is neither the plant's Business, a sharing partner nor the PLATFORM org, the answer stays 404.

Errors also 400, 403, 404, 409 VERSION_CONFLICT, 428.