normogen/web/normogen-web
goose d41256e05b fix(backend): flatten medication serialization (MedicationResponse)
Backend + frontend. Resolves the integration gap where the medication list/create
responses were deeply nested (fields inside medicationData.data JSON blob,
camelCase) while the frontend expected flat snake_case fields — so the
MedicationManager couldn't display real data.

Backend (models/medication.rs):
* New MedicationData struct: deserializes the camelCase JSON string stored in
  medicationData.data (sideEffects->side_effects, prescribedBy->prescribed_by,
  etc.). Tolerates missing keys via #[default].
* New MedicationResponse: flat snake_case, the wire format. From<Medication>
  deserializes the data blob, maps fields, synthesizes active=true (TODO: real
  active flag), formats timestamps as ISO 8601. Tolerates malformed blobs.
* Fixed MedicationRepository::update: the old dot-notation (medicationData.name)
  wrote into phantom paths because the stored shape is medicationData:{data:
  '<string>'}. Now loads the doc, deserializes the blob, applies overrides,
  re-serializes, and $sets the whole data string. Updates actually persist now.
* 4 new unit tests (MedicationData deser, defaults, MedicationResponse flatten,
  malformed-blob tolerance).

Handlers (handlers/medications.rs): create/list/get/update now return
MedicationResponse instead of the raw Medication model.

Frontend (types/api.ts): Medication interface reconciled to match
MedicationResponse (added id, profile_id, route, reason, side_effects,
prescribed_by/date, notes, tags; relaxed user_id to optional).

Verified: backend cargo fmt/build/clippy 0 warnings, 23 unit tests pass (was 19);
frontend npm build clean, 20 vitest tests pass.
2026-06-28 11:30:01 -03:00
..
public feat(web): Phase 3a — migrate CRA to Vite + make the app runnable 2026-06-28 00:47:19 -03:00
src fix(backend): flatten medication serialization (MedicationResponse) 2026-06-28 11:30:01 -03:00
.env.example feat(web): Phase 3a — migrate CRA to Vite + make the app runnable 2026-06-28 00:47:19 -03:00
.gitignore feat(web): Phase 3a — migrate CRA to Vite + make the app runnable 2026-06-28 00:47:19 -03:00
index.html feat(web): Phase 3a — migrate CRA to Vite + make the app runnable 2026-06-28 00:47:19 -03:00
package-lock.json feat: Phase 3c — dose logging + adherence, profile management, tests 2026-06-28 10:32:28 -03:00
package.json feat: Phase 3c — dose logging + adherence, profile management, tests 2026-06-28 10:32:28 -03:00
tsconfig.json feat(web): Phase 3a — migrate CRA to Vite + make the app runnable 2026-06-28 00:47:19 -03:00
tsconfig.node.json feat(web): Phase 3a — migrate CRA to Vite + make the app runnable 2026-06-28 00:47:19 -03:00
vite.config.ts feat(web): Phase 3a — migrate CRA to Vite + make the app runnable 2026-06-28 00:47:19 -03:00