Fix PocketBase date query - use range operators not contains
All checks were successful
Deploy / deploy (push) Successful in 1m39s
All checks were successful
Deploy / deploy (push) Successful in 1m39s
The ~ contains operator doesn't work with PocketBase date fields. Use >= and < operators with YYYY-MM-DD format instead, matching the working /api/history pattern. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -74,16 +74,20 @@ 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 YYYY-MM-DD format with contains operator for PocketBase date field
|
||||
// PocketBase filters don't accept ISO format with T separator
|
||||
// Use YYYY-MM-DD format with >= and < operators for PocketBase date field
|
||||
// PocketBase accepts simple date strings in comparison operators
|
||||
const today = new Date().toISOString().split("T")[0];
|
||||
const tomorrow = new Date(Date.now() + 86400000)
|
||||
.toISOString()
|
||||
.split("T")[0];
|
||||
|
||||
logger.info({ userId: user.id, date: today }, "Fetching dailyLog");
|
||||
logger.info({ userId: user.id, today, tomorrow }, "Fetching dailyLog");
|
||||
const dailyLog = await pb
|
||||
.collection("dailyLogs")
|
||||
.getFirstListItem<DailyLog>(`user="${user.id}" && date~"${today}"`, {
|
||||
sort: "-created",
|
||||
});
|
||||
.getFirstListItem<DailyLog>(
|
||||
`user="${user.id}" && date>="${today}" && date<"${tomorrow}"`,
|
||||
{ sort: "-created" },
|
||||
);
|
||||
|
||||
logger.info(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user