Fix PocketBase query error by sorting by date instead of created
All checks were successful
Deploy / deploy (push) Successful in 2m28s

The sort=-created parameter was causing PocketBase to return a 400 error
when querying dailyLogs. This is likely a compatibility issue with how
PocketBase handles the auto-generated 'created' field in certain query
combinations. Changing to sort by -date resolves the issue and makes
more semantic sense for dailyLogs which have one record per day.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-15 21:55:41 +00:00
parent 3e2d9047fb
commit a184909957

View File

@@ -71,7 +71,7 @@ export const GET = withAuth(async (_request, user, pb) => {
} }
// Try to fetch today's DailyLog for biometrics // Try to fetch today's DailyLog for biometrics
// Sort by created DESC to get the most recent record if multiple exist // Sort by date DESC to get the most recent record if multiple exist
let biometrics = { ...DEFAULT_BIOMETRICS, phaseLimit }; let biometrics = { ...DEFAULT_BIOMETRICS, phaseLimit };
try { try {
// Use YYYY-MM-DD format with >= and < operators for PocketBase date field // Use YYYY-MM-DD format with >= and < operators for PocketBase date field
@@ -86,7 +86,7 @@ export const GET = withAuth(async (_request, user, pb) => {
.collection("dailyLogs") .collection("dailyLogs")
.getFirstListItem<DailyLog>( .getFirstListItem<DailyLog>(
`user="${user.id}" && date>="${today}" && date<"${tomorrow}"`, `user="${user.id}" && date>="${today}" && date<"${tomorrow}"`,
{ sort: "-created" }, { sort: "-date" },
); );
logger.info( logger.info(