From 599a66bbb5ba3c0d080252094b540e7ad0844fb2 Mon Sep 17 00:00:00 2001 From: Petru Paler Date: Thu, 15 Jan 2026 14:25:16 +0000 Subject: [PATCH] Sort dailyLogs by created DESC to get most recent record When multiple dailyLog records exist for the same date (from multiple syncs), getFirstListItem was returning the oldest one with stale data. Now sorts by -created to return the most recent record. Co-Authored-By: Claude Opus 4.5 --- src/app/api/today/route.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/api/today/route.ts b/src/app/api/today/route.ts index ae2a344..5d2eb75 100644 --- a/src/app/api/today/route.ts +++ b/src/app/api/today/route.ts @@ -71,12 +71,15 @@ export const GET = withAuth(async (_request, user, pb) => { } // Try to fetch today's DailyLog for biometrics + // Sort by created DESC to get the most recent record if multiple exist let biometrics = { ...DEFAULT_BIOMETRICS, phaseLimit }; try { const today = new Date().toISOString().split("T")[0]; const dailyLog = await pb .collection("dailyLogs") - .getFirstListItem(`user="${user.id}" && date~"${today}"`); + .getFirstListItem(`user="${user.id}" && date~"${today}"`, { + sort: "-created", + }); biometrics = { hrvStatus: dailyLog.hrvStatus,