Sort dailyLogs by created DESC to get most recent record
All checks were successful
Deploy / deploy (push) Successful in 1m38s
All checks were successful
Deploy / deploy (push) Successful in 1m38s
When multiple dailyLog records exist for the same date (from multiple syncs), getFirstListItem was returning the oldest one with stale data. Now sorts by -created to return the most recent record. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,12 +71,15 @@ 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
|
||||||
let biometrics = { ...DEFAULT_BIOMETRICS, phaseLimit };
|
let biometrics = { ...DEFAULT_BIOMETRICS, phaseLimit };
|
||||||
try {
|
try {
|
||||||
const today = new Date().toISOString().split("T")[0];
|
const today = new Date().toISOString().split("T")[0];
|
||||||
const dailyLog = await pb
|
const dailyLog = await pb
|
||||||
.collection("dailyLogs")
|
.collection("dailyLogs")
|
||||||
.getFirstListItem<DailyLog>(`user="${user.id}" && date~"${today}"`);
|
.getFirstListItem<DailyLog>(`user="${user.id}" && date~"${today}"`, {
|
||||||
|
sort: "-created",
|
||||||
|
});
|
||||||
|
|
||||||
biometrics = {
|
biometrics = {
|
||||||
hrvStatus: dailyLog.hrvStatus,
|
hrvStatus: dailyLog.hrvStatus,
|
||||||
|
|||||||
Reference in New Issue
Block a user