Skip to content

feat: assign an Assessment to a crew — a crew read route and the crew picker - #627

Merged
phamtruonghung merged 1 commit into
mainfrom
feat/assessment-crew-picker
Nov 27, 2026
Merged

phamtruonghung merged 1 commit into
mainfrom
feat/assessment-crew-picker

Conversation

@phamtruonghung

Copy link
Copy Markdown
Owner

What

A Team Leader can now assign an Assessment to a crew, both on the create form and in the assign dialog. Before this, the API accepted crewIds but nothing could list crews. The client said so outright: "Crews have no client surface yet".

Server (People)

  • GET /api/people/sites/:siteId/crews?search=&includeInactive= returns { crews: [{ id, siteId, code, name, isActive, employeeCount }], truncated }, ordered by name. It is gated by Site scope plus the existing PPL_ORG_UNITS_DISPLAY. No new permission code and no migration.
  • employeeCount uses the same resolver as assign (RESOLVED_EMPLOYEES_SQL, now in sql.js and shared, not copied). That resolver takes the crew from the current assignment, else default_crew_id, active Employees only. So the number on the chip is the number of Attempts the crew alone would create.
  • assign now returns 400 for an unknown crew id. It also returns 400 for a named crew that reaches nobody, with a message that names it (crew X (Name) reaches nobody — no active Employee is on it), even when the rest of the group does reach people.

Client

  • A crew search sits between the Org Unit and Employee searches in assessment_create_screen.dart and assessment_assign_dialog.dart. Each chip shows the crew name and its Employee count. Preview and submit send crewIds.
  • New Crew model and PeopleApi.searchCrews. ARB keys are added in both app_en.arb and app_vi.arb (Tổ ca).

Decisions

  • The route is per Site rather than a bare /crews, because crews carry site_id and the picker already searches within the Assessment's Site.
  • There is no orgUnitName: the crews table has no Org Unit column.

Out of scope

Crew create, rename and retire. Nothing in the app manages crews today. Rows exist only through seeds and data loads. That needs its own card and its own decision.

Tests

  • backend/test/integration/people-crews.test.js covers the list with the member count (one member via an open assignment, one via default_crew_id only, an inactive Employee excluded), search, includeInactive, 403 without the code, 404 for an unknown Site, a zero-member crew refused by assign with its code named and no Attempts written, and a preview of crew + Org Unit + Employee that counts each person once and matches the Attempts that assign creates.
  • Widget tests: assessment_detail_test.dart, "a Crew picked in the assign dialog shows its member count, is previewed, and is sent on confirm". assessment_create_test.dart covers picking a crew, the chip count, the preview crewIds, and the assign body carrying the crew id.

Checks (run on head)

  • npm run lint: module boundaries: ok, syntax: checked 245 files
  • npm test: 58/58 pass
  • npm run test:integration on a freshly migrated scratch DB: 1405 tests, 1399 pass, 0 fail, 6 skipped. Four are the expected rls.test.js anon/authenticated skips. Two are the plant data load skipping because no employee master file exists in a local checkout.
  • ./scripts/flutter-ci.sh (pinned 3.44.0): No issues found!, module seams ok, All tests passed! (2149). No golden file changed.
  • bash scripts/design_gate.sh: 15 of 17 mismatches are AA noise. The other 2 are flagged for review: home_wide_en and home_wide_vi, which differ only in card-border antialiasing on the Home screen. This PR does not touch that screen. The gate rendered with the host's non-pinned Flutter, and the pinned image passes those same goldens.

Part of #588

… picker

The assign and preview routes already took crewIds, but nothing listed a
Site's crews, so neither the create form nor the assign dialog could offer
one. GET /api/people/sites/:siteId/crews returns a Site's active crews
(inactive only with includeInactive=true), searchable by code or name and
capped like the Org Unit search. It is gated by Site scope and
PPL_ORG_UNITS_DISPLAY, and each crew carries an employeeCount. That count
and assign share one RESOLVED_EMPLOYEES_SQL, now in sql.js, so the number
shown is the number of Attempts the crew alone would create. Inside its
transaction, assign now refuses an unknown crew id, or a crew that reaches
nobody, naming the crew by code and name. Both screens gain an "Add a crew"
search between the Org Unit and Employee searches. Its chips show the
crew's name and member count, preview and submit send crewIds, and the
empty-group rule counts crews. Strings are in both ARBs.

Part of #588

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@phamtruonghung
phamtruonghung merged commit 8ee1842 into main Nov 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant