mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
fix(api): one helper for list pages, exact cut signal, total order
listPage (src/lib/http/list-query.ts) reads one row past the limit and cuts it back, on top of the existing list-cap signal rather than beside it. Every capped list now gets its page there, and every read passed to it orders by something ending in the row id, so rows that share a sort value cannot repeat or vanish at a page boundary. - practitioners, vaccinations and encounters were cut at their take with no signal; they now answer meta.truncated and accept offset, and their web readers walk the pages instead of stopping at the first - symptoms/events reported hasMore on a page that was exactly full; it is now true only when a row past the page exists - the document list's hand-rolled limit + 1 goes through the helper - security-activity answers an out-of-range limit with the 422 its published schema already promised instead of clamping it list-page-guard binds every apiListSuccess route to listPage, forbids hand-cut lists and length-derived hasMore, and requires the id tiebreaker in every listPage read.
This commit is contained in:
1 parent
2265763160
commit
8db7c71b0e
35 files changed
+1024
-394
No files matched your search
@@ -26,6 +26,8 @@ import {
|
||||
safeJson,
|
||||
} from "@/lib/api-response";
|
||||
import { checkRecordWriteRateLimit } from "@/lib/rate-limit";
|
||||
import { apiListSuccess } from "@/lib/api/list-cap";
|
||||
import { combinedCap, listPage } from "@/lib/http/list-query";
|
||||
import { withIdempotency } from "@/lib/idempotency";
|
||||
import { encryptToBytes } from "@/lib/ai/coach/bytes-codec";
|
||||
import {
|
||||
@@ -109,27 +111,33 @@ export const GET = apiHandler(async (request: NextRequest) => {
|
||||
// past reads newest-first, which is the opposite direction; resolving both
|
||||
// here means the client renders two lists instead of splitting and
|
||||
// re-sorting one, and the ordering lives in one place.
|
||||
const [upcoming, past] = await Promise.all([
|
||||
prisma.encounter.findMany({
|
||||
// `gt` and `gte` are different keys, so the caller's lower bound and this
|
||||
// arm's floor both survive the spread; only the `lte` pair collided.
|
||||
where: { ...where, occurredAt: { ...where.occurredAt, gt: now } },
|
||||
orderBy: [{ occurredAt: "asc" }, { id: "asc" }],
|
||||
take,
|
||||
skip,
|
||||
include: ENCOUNTER_INCLUDE,
|
||||
}),
|
||||
prisma.encounter.findMany({
|
||||
where: {
|
||||
...where,
|
||||
occurredAt: { ...where.occurredAt, lte: pastCeiling },
|
||||
},
|
||||
orderBy: [{ occurredAt: "desc" }, { id: "desc" }],
|
||||
take,
|
||||
skip,
|
||||
include: ENCOUNTER_INCLUDE,
|
||||
}),
|
||||
]);
|
||||
const [{ rows: upcoming, cap: upcomingCap }, { rows: past, cap: pastCap }] =
|
||||
await Promise.all([
|
||||
listPage(take, (overTake) =>
|
||||
prisma.encounter.findMany({
|
||||
// `gt` and `gte` are different keys, so the caller's lower bound and
|
||||
// this arm's floor both survive the spread; only the `lte` pair
|
||||
// collided.
|
||||
where: { ...where, occurredAt: { ...where.occurredAt, gt: now } },
|
||||
orderBy: [{ occurredAt: "asc" }, { id: "asc" }],
|
||||
take: overTake,
|
||||
skip,
|
||||
include: ENCOUNTER_INCLUDE,
|
||||
}),
|
||||
),
|
||||
listPage(take, (overTake) =>
|
||||
prisma.encounter.findMany({
|
||||
where: {
|
||||
...where,
|
||||
occurredAt: { ...where.occurredAt, lte: pastCeiling },
|
||||
},
|
||||
orderBy: [{ occurredAt: "desc" }, { id: "desc" }],
|
||||
take: overTake,
|
||||
skip,
|
||||
include: ENCOUNTER_INCLUDE,
|
||||
}),
|
||||
),
|
||||
]);
|
||||
|
||||
// The links ride the list. The card counts what a visit produced, and the
|
||||
// edit sheet seeds its pickers from the row it was handed — a list without
|
||||
@@ -152,7 +160,7 @@ export const GET = apiHandler(async (request: NextRequest) => {
|
||||
upcoming: upcoming.map((row) => toEncounterDTO(row, links.get(row.id))),
|
||||
past: past.map((row) => toEncounterDTO(row, links.get(row.id))),
|
||||
};
|
||||
return apiSuccess(body);
|
||||
return apiListSuccess(body, combinedCap(upcomingCap, pastCap));
|
||||
});
|
||||
|
||||
// A double-tap on "save" must not file the same visit twice.
|
||||
|
||||
Reference in new issue
Block a user