fix(portal): implement PATCH /portal/pets/:petId + enrich GET (GRO-2187, fixes GRO-1480 §5.23) #165
Reference in New Issue
Block a user
Delete Branch "fix/gro-2187-portal-pets-patch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What & why
UAT §5.23 (parent GRO-1480) failed: the customer portal pet-save calls
PATCH /api/portal/pets/{petId}, which the deployedsrc/tree never registered → 404, no persistence.GET /portal/petsalso omitted the extended fields, so a write would not be visible on reload.Gitea source-of-truth issue: groombook/api #162.
Changes (
src/routes/portal.ts)PATCH /portal/pets/:petIdwith ownership enforcement (pet.clientId === portalClientId→ 403; missing pet → 404), mirroring the appointment-notes handler.weightKg/weight), dateOfBirth (birthDate), groomingNotes (notes), healthAlerts, photoKey (photoUrl), coatType, petSizeCategory (webxlarge→ DBextra_large), preferredCuts, medicalAlerts; setsupdatedAt. The web form spreads the GET-shaped pet plus its own edited keys, so both spellings are accepted.coatType/petSizeCategory→ 422 (validated in-handler; zValidator failures would surface as 400).GET /portal/petsenriched with coatType, petSizeCategory, healthAlerts, preferredCuts, medicalAlerts.src/__tests__/portalPets.test.ts): owner success + persistence, weight fallback, non-owner 403, not-found 404, invalid enum 422 (coat + size), missing-session 401.The
coatType/petSizeCategoryenums were already present inpackages/db/src/schema.ts(no change needed).UAT Playbook
Updated
UAT_PLAYBOOK.md§4.8 (Customer Portal) — added TC-API-8.12 (GET extended fields), TC-API-8.13 (owner PATCH success + persistence,xlarge→extra_large), TC-API-8.14 (non-owner blocked), TC-API-8.15 (invalid enum 422).Verification
pnpm test— 582 passed (incl. 7 new portal-pet tests, bothsrc/andapps/api/trees).pnpm typecheck— clean.cc @cpfarhood
The customer portal pet-save calls PATCH /api/portal/pets/{petId}, which the deployed src/ tree never registered → 404, no persistence (UAT §5.23 / GRO-1480 regression). Also GET /portal/pets omitted the extended fields, so a write was not visible on reload. - Add portalRouter.patch("/pets/:petId", …) with ownership enforcement (pet.clientId === portalClientId → 403, missing pet → 404), mirroring the appointment-notes handler. - Map the web payload to pets columns: name, breed, weightKg (accept weightKg/weight), dateOfBirth (birthDate), groomingNotes (notes), healthAlerts, photoKey (photoUrl), coatType, petSizeCategory (web "xlarge" → DB "extra_large"), preferredCuts, medicalAlerts; set updatedAt. - Reject invalid coatType/petSizeCategory with 422 (validated in-handler). - Enrich GET /portal/pets with coatType, petSizeCategory, healthAlerts, preferredCuts, medicalAlerts. - Add src/__tests__/portalPets.test.ts: owner success + persistence, weight fallback, non-owner 403, not-found 404, invalid enum 422, missing session 401. - UAT_PLAYBOOK.md §4.8: add TC-API-8.12–8.15 for portal pet GET/PATCH. coatType/petSizeCategory enums already present in packages/db/src/schema.ts. Co-Authored-By: Paperclip <noreply@paperclip.ing>