fix(measurements): accept deviceType on single-entry POST (mirrors batch route)

`Measurement.deviceType` exists on the row, was added by the W8c
batch ingest path, but the single-entry `createMeasurementSchema`
omitted it — every single-row POST silently dropped the device tag
even when the client supplied one. Manual rows tagged with watch /
scale / ring metadata lost their attribution at the schema boundary
and showed up as unsourced.

Declare `deviceType` on the schema (optional, nullable, 1–32 chars),
thread it through both single-entry and array-body POST handlers,
and add three RTL cases (present, null, omitted) so the parsed
shape stays observable.
This commit is contained in:
Marc-André Bombeck committed 2026-05-14 16:56:06 +02:00
1 parent 72fcdc656f
commit c49fe731e4
3 files changed
+60 -1

No files matched your search

+10 -1
View File
@@ -96,6 +96,10 @@ async function postMeasurement(request: NextRequest) {
notes: m.notes ?? null,
glucoseContext:
(m.glucoseContext as GlucoseContext | undefined) ?? null,
// v1.4.25 W10 reconcile (code-review M4): mirror the
// single-entry path so the multi-entry batch persists
// `deviceType` instead of silently dropping it.
deviceType: m.deviceType ?? null,
},
}),
),
@@ -127,7 +131,7 @@ async function postMeasurement(request: NextRequest) {
return apiError(parsed.error.issues[0].message, 422);
}
const { type, value, measuredAt, notes, source, glucoseContext } =
const { type, value, measuredAt, notes, source, glucoseContext, deviceType } =
parsed.data;
// Handle unique constraint violation
@@ -143,6 +147,11 @@ async function postMeasurement(request: NextRequest) {
measuredAt,
notes: notes ?? null,
glucoseContext: (glucoseContext as GlucoseContext | undefined) ?? null,
// v1.4.25 W10 reconcile (code-review M4): the deviceType column
// already accepts client metadata from the batch route. Mirror
// the behaviour here so single-entry POST persists the tag
// instead of silently dropping it.
deviceType: deviceType ?? null,
},
});
} catch (err) {