feat(nutrients): carry daily targets through backup, wipe and the API contract

Nutrient targets travel in the account-settings slice of the full
backup and are admitted code by code on restore, so an unknown code or
an out-of-range value is dropped and named while the rest come back. A
data wipe clears them. The targets route joins the OpenAPI registry,
and the regenerated contract carries the wider nutrient enums, the new
sources and the target and authority fields. Refs #1402.
This commit is contained in:
Marc-André Bombeck committed 2026-11-17 19:05:31 +01:00
1 parent 7c40ba8202
commit db0e4f9688
18 files changed
+1470 -381

No files matched your search

+56
View File
@@ -23,12 +23,17 @@ import {
nutrientWaterWriteSchema,
nutrientWaterWriteResponseSchema,
} from "@/lib/validations/nutrients";
import {
nutrientTargetsPatchSchema,
nutrientTargetsResponseSchema,
} from "@/lib/validations/nutrient-targets";
import {
dataEnvelope,
errorEnvelope,
idempotencyKeyParameter,
idempotentWrite,
recordRefusal,
recordWriteRateLimitResponse,
stdResponses,
} from "./shared";
@@ -216,4 +221,55 @@ export const nutrientPaths: NonNullable<ZodOpenApiObject["paths"]> = {
},
},
},
"/api/nutrients/targets": {
get: {
tags: ["Nutrients"],
summary: "Daily nutrient targets",
description:
"The daily targets the person set for themselves, keyed by catalog code, each `{ value, direction }` in the code's canonical unit: `target` is an amount to reach, `limit` one to stay under. Only codes with a target appear; there is no default. Owner only. `GET /api/nutrients/daily` carries the one for its code as `personalTarget`. Behind the opt-in `nutrients` module.",
responses: {
"200": {
description: "The targets.",
content: {
"application/json": {
schema: dataEnvelope(
nutrientTargetsResponseSchema,
"NutrientTargetsEnvelope",
),
},
},
},
...moduleDisabled,
...stdResponses,
},
},
patch: {
tags: ["Nutrients"],
summary: "Set daily nutrient targets",
description:
"Sets the targets the body names and keeps the rest; `null` clears one. An unknown code, or a value at or below 0 or above the code's plausibility cap, is refused with the multi-issue 422. Owner only: a shared or delegated session cannot change another person's targets. Behind the opt-in `nutrients` module.",
requestBody: {
required: true,
content: {
"application/json": { schema: nutrientTargetsPatchSchema },
},
},
responses: {
"200": {
description: "The targets after the change.",
content: {
"application/json": {
schema: dataEnvelope(
nutrientTargetsResponseSchema,
"NutrientTargetsPatchEnvelope",
),
},
},
},
...moduleDisabled,
...stdResponses,
...recordWriteRateLimitResponse,
},
},
},
};