feat: let an account choose the unit its glucose is shown in

`User.glucoseUnit` has existed since v1.2 and around thirty surfaces read
it — the dashboard tiles, the glucose page, the targets panel, the CSV and
FHIR exports, the doctor report, the Coach snapshot, the low-reading push
copy. Nothing could ever write it. No route, no schema, no field on any
form, so every account resolved to the mg/dL default and the mmol/L half
of the app was unreachable code. Anyone who reads glucose in mmol/L
converted in their head on every screen.

This is the missing end: a `GET`/`PATCH /api/auth/me/glucose-unit` scalar
on the pattern the unit-preference endpoint next door established, and a
dropdown in the profile form beside it. Deliberately its own control
rather than a branch of metric/imperial: metric countries are split on
which unit they read glucose in, so one dropdown would get half of them
wrong.

Storage is untouched and stays untouched. Every reading is written in
mg/dL by every ingest path and the unit only selects a display branch, so
nothing already recorded is reinterpreted. The entry form moved with the
preference, which is the half that could have hurt: it asks in the chosen
unit and inverts through `toCanonicalMgdl` on submit, so a 5.3 typed by an
mmol/L reader is filed as 95 mg/dL rather than as 5.3 — a value the
plausibility band accepts in silence and every surface reads back as a
severe hypo.

The contract gains the endpoint and nothing else; the account payload
already carried the field.
This commit is contained in:
Marc-André Bombeck committed 2026-09-03 06:05:58 +02:00
1 parent 841593a5b2
commit 5078867203
18 files changed
+1005 -21

No files matched your search

+112
View File
@@ -7759,6 +7759,62 @@ paths:
$ref: "#/components/schemas/ErrorEnvelope"
"422": *a4
"429": *a5
/api/auth/me/glucose-unit:
get:
tags:
- Auth
summary: Read the blood-glucose display unit
description: Which unit blood-glucose readings are rendered in — `mg/dL` or `mmol/L`. A separate choice from the
metric/imperial preference, because metric countries are split on which one they read glucose in. Canonical
storage is mg/dL on every reading and every ingest path; this changes presentation only. Any stored value other
than `mmol/L` resolves to `mg/dL`, including a null on an account that never set it.
responses:
"200":
description: The resolved unit.
content:
application/json:
schema:
$ref: "#/components/schemas/GetGlucoseUnitEnvelope"
"401": *a1
"422": *a4
"429": *a5
patch:
tags:
- Auth
summary: Set the blood-glucose display unit
description: >-
Hard-set, idempotent, audit-logged. Rate-limited 60 / min per user.
Nothing already stored is converted or reinterpreted: readings stay mg/dL, and a value typed into the entry form
in mmol/L is inverted to mg/dL before it is written.
The body is capped at 1 KB and must carry `Content-Type: application/json`. Anything larger is 413, a wrong
content type is 415, and a body that is not JSON at all is 400 — the same three the other scalars in this group
answer.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/GlucoseUnitPatchRequest"
responses:
"200":
description: The resolved next unit.
content:
application/json:
schema:
$ref: "#/components/schemas/PatchGlucoseUnitEnvelope"
"401": *a1
"413":
description: Request body exceeds 1024 bytes. Nothing was written.
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorEnvelope"
"422": *a4
"429": *a5
/api/auth/me/documents-auto-ai-read:
get:
tags:
@@ -23141,6 +23197,17 @@ components:
required:
- unitPreference
description: Which display-unit branch to render. Presentation only — the stored measurement rows stay SI either way.
GlucoseUnitPatchRequest:
type: object
properties:
glucoseUnit:
type: string
enum:
- mg/dL
- mmol/L
required:
- glucoseUnit
description: Which unit blood-glucose readings are rendered in. Presentation only — every stored reading is mg/dL either way.
DocumentsAutoAiReadPatchRequest:
type: object
properties:
@@ -45799,6 +45866,51 @@ components:
- data
- error
additionalProperties: false
GetGlucoseUnitEnvelope:
type: object
properties:
data:
$ref: "#/components/schemas/GlucoseUnitResponse"
error:
type: "null"
meta:
type: object
properties:
requestId:
type: string
additionalProperties: false
required:
- data
- error
additionalProperties: false
GlucoseUnitResponse:
type: object
properties:
glucoseUnit:
type: string
enum:
- mg/dL
- mmol/L
required:
- glucoseUnit
additionalProperties: false
PatchGlucoseUnitEnvelope:
type: object
properties:
data:
$ref: "#/components/schemas/GlucoseUnitResponse"
error:
type: "null"
meta:
type: object
properties:
requestId:
type: string
additionalProperties: false
required:
- data
- error
additionalProperties: false
GetDocumentsAutoAiReadEnvelope:
type: object
properties: