Fix dailyLog date query to use proper date comparison
All checks were successful
Deploy / deploy (push) Successful in 1m40s

- Change /api/today query from string contains (~) to date range (>=, <)
- Store dates in full ISO format in garmin-sync for consistent comparison
- PocketBase date fields need proper date operators, not string contains

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-15 14:37:53 +00:00
parent f923e1ce48
commit 5f8e913555
4 changed files with 31 additions and 12 deletions

View File

@@ -74,13 +74,24 @@ export const GET = withAuth(async (_request, user, pb) => {
// 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];
logger.info({ userId: user.id, today }, "Fetching dailyLog");
// Use date range query for proper date field comparison
// PocketBase date fields need >= and < operators, not string contains
const todayStart = new Date();
todayStart.setUTCHours(0, 0, 0, 0);
const tomorrowStart = new Date(todayStart.getTime() + 86400000);
const todayISO = todayStart.toISOString();
const tomorrowISO = tomorrowStart.toISOString();
logger.info(
{ userId: user.id, todayISO, tomorrowISO },
"Fetching dailyLog",
);
const dailyLog = await pb
.collection("dailyLogs")
.getFirstListItem<DailyLog>(`user="${user.id}" && date~"${today}"`, {
sort: "-created",
});
.getFirstListItem<DailyLog>(
`user="${user.id}" && date>="${todayISO}" && date<"${tomorrowISO}"`,
{ sort: "-created" },
);
logger.info(
{