Fix dailyLog date query to use proper date comparison
All checks were successful
Deploy / deploy (push) Successful in 1m40s
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:
@@ -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(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user