AladiaDocs

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); placements FIELD_PLACEMENTS (:25): request|checkout|registration;
  • fieldDraftErrors (:91): label 1–80, valid type on creation, choices with ≥ 2 distinct options (max 50), file only in request;
  • 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 (request only, with required overridden);
  • cleanFieldValue/cleanFieldValues (:156, :208): per-type cleaning (lowercase email, comma decimals, YYYY-MM-DD dates, 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 is lib/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. Index owner.id+order. At most 50 active.
  • workspace_field_values (workspace-field-value.model.ts): owner, email (lowercase), profileId?, values {fieldId: value}. Unique owner.id+email; sparse owner.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:

RouteGuard
GET /v2/workspace-fields?archived=truesession (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/:fileIdleads.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

  1. POST public/leads/uploads → signed PUT URL in the workspace bucket (SignedUploadDto.forBrowserPut(owner), no metadata);
  2. the browser uploads (putSigned) and sends { uploadId, name, contentType, size } in the form;
  3. on submission the gateway (registerUploads, leads.service.ts:161) creates the File record with registerUploadedFile(..., isPublic: false) and passes { fileId, name };
  4. 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 override components/leads/course-form-section.tsx in /settings/leads.
  • Forms: components/fields/field-input.tsx (kit controls per type, file upload), in LeadForm (outside react-hook-form since they're dynamic, validated with fieldError), at sign-up components/fields/signup-fields.tsx (fields placed in registration on the workspace site, kept in sessionStorage until verification, saved with fields/me then removed; Google skips the form).
  • Columns: Requests (leads-view.tsx: column, kit filter per type filterTypeOf, 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 from values/search for 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.

On this page