fix(measurements): answer the day drill-down without the sealed note

The dayKey drill-down of GET /api/measurements answered the stored rows as
they were, notesEncrypted ciphertext included and the note itself unread.
It now selects the contract's columns by name and shapes each row like the
plain page: the note decrypted onto notes, the ciphertext never on the wire.

A route test walks the measurement reads over rows with a sealed note
(the page, the drill-down, the day-grouped list, an aggregate, the detail)
and fails on any sealed field; it failed on the drill-down before this
change. The parity walk drops its contract exemption for the drill-down.
This commit is contained in:
Marc-André Bombeck committed 2026-10-23 13:41:11 +02:00
1 parent 7b9737c7b1
commit 3f8c2a98dd
4 files changed
+148 -14

No files matched your search

+36 -2
View File
@@ -28,7 +28,38 @@ import {
import { dayGroupedListResponse } from "@/lib/measurements/list/day-grouped";
import { sleepListResponse } from "@/lib/measurements/list/sleep-list";
import { resolveStoredTimezone, resolveUserTimezone } from "@/lib/tz/resolver";
import type { MeasurementType } from "@/generated/prisma/client";
import type { MeasurementType, Prisma } from "@/generated/prisma/client";
/**
* The columns a measurement row answers with (`MeasurementResource`), plus
* the sealed note `shapeMeasurementNotes` decrypts onto `notes` and drops.
* Named column by column so a column added to the model reaches the wire
* only when someone adds it here.
*/
const MEASUREMENT_WIRE_SELECT = {
id: true,
userId: true,
type: true,
value: true,
valueMin: true,
valueMax: true,
unit: true,
source: true,
measuredAt: true,
notes: true,
notesEncrypted: true,
externalId: true,
externalSourceVersion: true,
aggregationProvenance: true,
glucoseContext: true,
sleepStage: true,
rhythmClassification: true,
deviceType: true,
syncVersion: true,
deletedAt: true,
createdAt: true,
updatedAt: true,
} as const satisfies Prisma.MeasurementSelect;
type ListQuery = z.output<typeof listMeasurementsSchema>;
type ListUser = { id: string; timezone: string | null };
@@ -162,13 +193,16 @@ async function drillDownResponse(
// returning 422 when a caller asks for more). `limit` is read straight
// through because the validator has already clamped it.
take: limit,
select: MEASUREMENT_WIRE_SELECT,
});
annotate({
action: { name: "measurement.list" },
meta: { total: samples.length, type, dayKey, mode: "drill-down" },
});
return apiSuccess({
measurements: samples,
// The same row shape as the plain page: the note decrypted onto `notes`,
// the ciphertext never on the wire.
measurements: samples.map(shapeMeasurementNotes),
meta: { total: samples.length, limit, offset: 0, dayKey },
});
}