From 7c9faba215461a7d30689b597417c114c78d40aa Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Tue, 30 Jun 2026 11:06:58 +0000 Subject: [PATCH] sort dupe files based on upload timestamp rather than id --- src/app/api/live-tracking/property-documents/route.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/api/live-tracking/property-documents/route.ts b/src/app/api/live-tracking/property-documents/route.ts index 6d5ee7f6..c8821de6 100644 --- a/src/app/api/live-tracking/property-documents/route.ts +++ b/src/app/api/live-tracking/property-documents/route.ts @@ -48,7 +48,9 @@ export async function GET(req: Request) { const latestByS3Key = new Map(); for (const row of rows) { const existing = latestByS3Key.get(row.s3FileKey); - if (!existing || row.id > existing.id) latestByS3Key.set(row.s3FileKey, row); + if (!existing || row.s3UploadTimestamp > existing.s3UploadTimestamp) { + latestByS3Key.set(row.s3FileKey, row); + } } // Step 2: among distinct keys, same (fileType, measureName) → keep latest. @@ -59,7 +61,9 @@ export async function GET(req: Request) { if (!row.fileType) { unclassified.push(row); continue; } const key = `${row.fileType}:${row.measureName ?? ""}`; const existing = latestByDocType.get(key); - if (!existing || row.id > existing.id) latestByDocType.set(key, row); + if (!existing || row.s3UploadTimestamp > existing.s3UploadTimestamp) { + latestByDocType.set(key, row); + } } const dedupedRows = [...latestByDocType.values(), ...unclassified];