feat(glucose): add a diabetes opt-in preference

Introduce an explicit, user-declared "I have diabetes / clinician glucose
targets" preference (`User.hasDiabetes`, migration 0174, defaulted false) plus
its GET/PATCH endpoint at `/api/auth/me/diabetes`. The flag selects which
glucose target band a reading is judged against; it is never inferred from a
value and never asserts a diagnosis. Mirrors the existing per-user-scalar
preference pattern: 60/min rate limit, Zod validation, audit-logged,
field-by-field write. OpenAPI regenerated for the new route.
This commit is contained in:
Marc-André Bombeck committed 2026-06-18 20:17:13 +02:00
1 parent 1d83e10764
commit 2c87a93827
5 files changed
+294

No files matched your search

+99
View File
@@ -1837,6 +1837,8 @@ paths:
minLength: 1
maxLength: 32
- type: "null"
symptomsPresent:
type: boolean
required:
- type
- value
@@ -3170,6 +3172,48 @@ paths:
"401": *a1
"422": *a3
"429": *a4
/api/auth/me/diabetes:
get:
tags:
- Auth
summary: Read per-user diabetes opt-in flag
description: Returns the user's per-account diabetes opt-in flag. Default `false`. When `true`, the glucose target
resolver applies the tighter ADA glycemic GOAL bands (fasting 80–130, postprandial < 180) instead of the general
non-diabetic bands. Powers the Settings "I have diabetes / clinician glucose targets" toggle. Never inferred
from a reading; asserts no diagnosis.
responses:
"200":
description: Resolved flag.
content:
application/json:
schema:
$ref: "#/components/schemas/GetDiabetesResponse"
"401": *a1
"422": *a3
"429": *a4
patch:
tags:
- Auth
summary: Toggle per-user diabetes opt-in flag
description: Sets the per-account diabetes opt-in flag. Idempotent — the DB write fires even when the value matches so
the audit-log row mirrors the API call. Always returns the resolved next-state. `userId` is never accepted from
the body. Rate-limit 60/min per user.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/DiabetesFlag"
responses:
"200":
description: Resolved next-state echoed back for optimistic-update consumers.
content:
application/json:
schema:
$ref: "#/components/schemas/PatchDiabetesResponse"
"401": *a1
"422": *a3
"429": *a4
/api/auth/me/modules:
get:
tags:
@@ -7668,6 +7712,16 @@ components:
required:
- disableCoach
description: Per-account Coach opt-out toggle (v1.4.47 W3). `true` hides the Coach FAB and short-circuits its API gates.
DiabetesFlag:
type: object
properties:
hasDiabetes:
type: boolean
required:
- hasDiabetes
description: Per-account diabetes opt-in (v1.18.6). `true` selects the ADA glycemic GOAL bands (fasting 80–130,
postprandial < 180) for glucose targets instead of the general non-diabetic bands. A user-declared preference
only — never inferred from a value, never a diagnosis.
ModulePrefsPatchRequest:
type: object
properties:
@@ -13611,6 +13665,40 @@ components:
- data
- error
additionalProperties: false
GetDiabetesResponse:
type: object
properties:
data:
$ref: "#/components/schemas/DiabetesFlagOutput"
error:
type: "null"
meta:
type: object
properties:
requestId:
type: string
additionalProperties: false
required:
- data
- error
additionalProperties: false
PatchDiabetesResponse:
type: object
properties:
data:
$ref: "#/components/schemas/DiabetesFlagOutput"
error:
type: "null"
meta:
type: object
properties:
requestId:
type: string
additionalProperties: false
required:
- data
- error
additionalProperties: false
GetModulesResponse:
type: object
properties:
@@ -19607,6 +19695,17 @@ components:
- disableCoach
additionalProperties: false
description: Per-account Coach opt-out toggle (v1.4.47 W3). `true` hides the Coach FAB and short-circuits its API gates.
DiabetesFlagOutput:
type: object
properties:
hasDiabetes:
type: boolean
required:
- hasDiabetes
additionalProperties: false
description: Per-account diabetes opt-in (v1.18.6). `true` selects the ADA glycemic GOAL bands (fasting 80–130,
postprandial < 180) for glucose targets instead of the general non-diabetic bands. A user-declared preference
only — never inferred from a value, never a diagnosis.
InsightsLayoutBodyOutput:
type: object
properties: