feat(frontend): add need entity form model over the transport DTOs
This commit is contained in:
1 parent
cb2b990cd9
commit
3b917befa9
9 files changed
+1412
-2
No files matched your search
+13
-1
@@ -7,7 +7,7 @@ A React and TypeScript SPA built with Vite and organized using FSD. The interfac
|
||||
- `src/app/` starts the application: the route tree (`router/`), the query client (`providers/`), global styles, and the route error page.
|
||||
- `src/pages/` holds pages: `welcome` (start page), `placeholder` (screen placeholders and the screen map), `status` (technical status), `not-found`.
|
||||
- `src/widgets/` holds shells: `public-shell`, `candidate-shell`, `employer-shell`, plus the technical `system-status` widget.
|
||||
- `src/features/` and `src/entities/` are still empty.
|
||||
- `src/entities/` holds entities: `need` (the form model of an employer need, see [Need entity](#need-entity)); `src/features/` is still empty.
|
||||
- `src/shared/ui/` holds design tokens, fonts, logos, and primitives; `src/shared/config/` holds route paths; `src/shared/api/` holds the API client with generated endpoints, Zod schemas, and MSW mocks.
|
||||
- `codegen/orval.config.ts` configures generation from the shared OpenAPI contract; `codegen/mock-patterns.ts` is the step after Orval that fixes MSW mocks of strings with a `pattern` (see [API client generation](#api-client-generation)).
|
||||
- `scripts/` checks FSD boundaries and Orval compatibility with the OpenAPI 3.2 fixture.
|
||||
@@ -35,6 +35,18 @@ Generated Orval hooks call the shared same-origin `apiRequest` client, so the `Q
|
||||
- `staleTime` of 30 s; window focus does not refetch, and screens that need fresh data opt in per query;
|
||||
- mutations do not retry until the API supports `Idempotency-Key`.
|
||||
|
||||
## Need entity
|
||||
|
||||
`entities/need` converts the generated DTOs of the need contract (`Need`, `NeedCreate`, `NeedUpdate`) to a form model and back. It is pure functions without React and without its own store; server data stays in the TanStack Query cache. The need UI is not implemented yet.
|
||||
|
||||
- `fromTransport` builds a draft from a `Need`. Each requirement field is an explicit state: `unknown` without a value, `extracted` as a stored suggestion with its provenance and quote, and `confirmed` as a confirmed value. An unknown field never becomes an empty string, an empty list, or a default value; a skill outside the taxonomy keeps `taxonomy_code: null`. Data that breaks the rule "value and source are null exactly when unknown" is rejected with `NeedTransportError`.
|
||||
- `toUpdateBody(need, draft)` sends only the fields whose request value changed, plus the `expected_version` of the read version. An untouched suggestion is not sent; when its field or list is sent for another reason, it goes with status `extracted`. A cleared field is sent as null, an emptied list as `[]`, and an untouched list is absent.
|
||||
- `toCreateBody(draft)` always sends the title and leaves out unknown fields and empty lists, so the server extracts them from `source_text`.
|
||||
- The edit functions (`confirmField`, `setFieldValue`, `clearField`, `confirmSkill`, `moveSkill`, and others) keep the invariants: only an untouched suggestion has status `extracted`, an edited value becomes `confirmed`, and moving a skill between lists does not confirm it.
|
||||
- `validateNeedCreate` and `validateNeedUpdate` check the body with the generated Zod schemas and tie the problems to form fields. The server checks cross-field rules (the salary width, a repeated skill), and `needFormFieldOf` maps its pointer to a form field.
|
||||
|
||||
The tests take their fixtures from the named contract examples in `api/core/openapi.bundle.yml` and check every body with the generated `NeedCreate` and `NeedUpdate` schemas.
|
||||
|
||||
## API client generation
|
||||
|
||||
`make -C frontend generate` runs Orval with `codegen/orval.config.ts` and then `codegen/mock-patterns.ts`. For a string with a `pattern`, Orval 8.40 writes `faker.helpers.fromRegExp(pattern)` into the MSW mock: faker prints the `^` and `$` anchors and `(?:...)` groups as plain text, and Orval ignores `minLength` and `maxLength` when a `pattern` is present. The second step replaces such calls with `fakeFromPattern(pattern, {minLength, maxLength})` from `src/shared/api/mock-pattern.ts`. It takes the length bounds from the OpenAPI contract by the name of the property that holds the call and by the pattern. The step fails when a call has an unexpected form, when the contract has no such property with that pattern, or when the matching schemas disagree on the length bounds. It leaves its own output unchanged, so generation is reproducible and `make check-generated` stays stable. Enums in the mocks are written as literals (`enumGenerationType: "union"`): `Object.values` of a `zod.enum` returns Zod internals, not the values.
|
||||
|
||||
Reference in new issue
Block a user