Custom fields
Slice b of the academy website: field definitions, values per person (by email), request, checkout and sign-up forms, per-course override, private files, columns in People and Requests.
Status: branch release/checkout-leads (06/10/2026). Owner spec of 06/10 (point 4 and part of 5). Guide: Custom fields. Paths are relative to backend/ and web-next/.
1. Rules
libs/common/src/common/leads/workspace-fields.rules.ts:
- types
FIELD_TYPES(:22):text|textarea|email|phone|number|select|multiselect|date|boolean|file(the Document Builder question types plus personal-data ones); placementsFIELD_PLACEMENTS(:25):request|checkout|registration; fieldDraftErrors(:91): label 1–80, valid type on creation, choices with ≥ 2 distinct options (max 50), file only inrequest;normalizeOptions(:114): option ids stay (even when the client sends only the same text), new ones get a slug; renaming doesn't orphan values;formFieldsFor(:135): active fields of the placement, or the course override (requestonly, withrequiredoverridden);cleanFieldValue/cleanFieldValues(:156,:208): per-type cleaning (lowercase email, comma decimals,YYYY-MM-DDdates, existing options, file{fileId 24 hex, name}), required, required yes/no =true; fields outside the form are dropped;displayFieldValue(:224) for email and notices; the web-next twin islib/workspace-fields.ts.
2. Data model
workspace_fields(models/microservices/profile/workspace-field.model.ts):owner,label,help,type(fixed),required,options[] {id,label},placements[],order,archivedAt. Indexowner.id+order. At most 50 active.workspace_field_values(workspace-field-value.model.ts):owner,email(lowercase),profileId?,values {fieldId: value}. Uniqueowner.id+email; sparseowner.id+profileId. The person is recognised by email because requesters and buyers don't have an account yet; the profile is added when known (sign-up).lead_settings.courseForms[] {courseId, fields[] {fieldId, required?}}: a course's request form.leads.fields: the request values (copy at submission time).
3. Service (profile)
apps/profile/src/app/workspace-fields/workspace-fields.service.ts: list (:61), save creates/edits without changing the type (:70), archive/restore (:108), reorder (:126), formFields (:138, override from lead_settings), validate (:159, 400 workspace-field-invalid with details fields.<id>), saveValues/store (:175, :181, $set values.<id> = merged with known values), search by email (:197), canReadFile (:208: the file must be in a request or in the values of this workspace). LeadsService.create validates the course form fields and stores them both on the request and on the person; setCourseForm manages the override.
4. Routes (gateway)
apps/gateway/src/gateway/controllers/profile/leads/workspace-fields.controller.ts:
| Route | Guard |
|---|---|
GET /v2/workspace-fields?archived=true | session (definitions of the active workspace) |
POST /v2/workspace-fields, PATCH /:id, POST /:id/archive, POST /:id/restore, PUT /order {ids} | marketplace.update |
POST /v2/workspace-fields/values/search {emails} | leads.read |
GET /v2/workspace-fields/files/:fileId | leads.read + canReadFile → short signed URL (files.retrieve-signed-url) |
PUT /v2/leads/settings/courses/:courseId {fields} | marketplace.update (empty = drop the override) |
GET /v2/public/workspaces/:id/fields?type&placement= (checkout or registration) | public |
PUT /v2/public/workspaces/:id/fields/me {type, values} | session: own values only, registration placement |
POST /v2/public/leads/uploads {courseId, contentType, size} | public, 10/hour per IP (FixedWindowLimiter), only courses in request mode with a file field |
The public offer (leads.service.ts) carries the fields of the course request form and formOnPage = fields.length > 4 (DIALOG_FIELDS_THRESHOLD).
5. Private files
POST public/leads/uploads→ signed PUT URL in the workspace bucket (SignedUploadDto.forBrowserPut(owner), no metadata);- the browser uploads (
putSigned) and sends{ uploadId, name, contentType, size }in the form; - on submission the gateway (
registerUploads,leads.service.ts:161) creates the File record withregisterUploadedFile(..., isPublic: false)and passes{ fileId, name }; - staff open it from Requests with
GET workspace-fields/files/:fileId(ownership check, short signed URL).
Allowed types PDF/JPEG/PNG/WebP/HEIC, 10 MB (checked in the upload DTO and in the browser).
6. web-next
- Settings:
app/(app)/settings/fields/page.tsx("Custom fields" entry; active list with arrows, archived with Restore, centred dialog, full screen on mobile); per-course overridecomponents/leads/course-form-section.tsxin/settings/leads. - Forms:
components/fields/field-input.tsx(kit controls per type, file upload), inLeadForm(outside react-hook-form since they're dynamic, validated withfieldError), at sign-upcomponents/fields/signup-fields.tsx(fields placed inregistrationon the workspace site, kept insessionStorageuntil verification, saved withfields/methen removed; Google skips the form). - Columns: Requests (
leads-view.tsx: column, kit filter per typefilterTypeOf, CSV, detail with file link) and People (members-tab.tsx:field:<id>columns hidden by default before the actions, filter, CSV, views remember them; values fromvalues/searchfor the members' emails, 403 = empty columns).
7. Configuration
After the backend deploy: scripts/migrations/2026-10-workspace-fields.js (PHASE=plan|apply, indexes only). Needs slice a's migration (leads.read for values). Check: node web-next/e2e/help/flows/run.mjs leads/custom-fields --shots.
8. Tests
tests/unit/workspace-fields.spec.ts (per-type rules, stable options, placements and override, service: create/edit/order/archive, values merged by email, course override, files readable only by their workspace, request refused without a required field and values on the person); web-next lib/workspace-fields.test.mjs.