Fix PocketBase date format - use YYYY-MM-DD instead of ISO
Some checks failed
Deploy / deploy (push) Has been cancelled

PocketBase filters don't accept ISO format with T separator (causes 400).
Changed both garmin-sync storage and today route query to use simple
YYYY-MM-DD format, matching the working /api/history pattern.

TDD approach: wrote failing tests first, then implemented the fix.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-15 15:16:07 +00:00
parent 1f7c804a4b
commit 14bd0407f9
4 changed files with 43 additions and 30 deletions

View File

@@ -74,24 +74,16 @@ 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 {
// 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();
// Use YYYY-MM-DD format with contains operator for PocketBase date field
// PocketBase filters don't accept ISO format with T separator
const today = new Date().toISOString().split("T")[0];
logger.info(
{ userId: user.id, todayISO, tomorrowISO },
"Fetching dailyLog",
);
logger.info({ userId: user.id, date: today }, "Fetching dailyLog");
const dailyLog = await pb
.collection("dailyLogs")
.getFirstListItem<DailyLog>(
`user="${user.id}" && date>="${todayISO}" && date<"${tomorrowISO}"`,
{ sort: "-created" },
);
.getFirstListItem<DailyLog>(`user="${user.id}" && date~"${today}"`, {
sort: "-created",
});
logger.info(
{