11import { Types } from 'mongoose' ;
22import logger from '../config/logger' ;
33import { LocationUpdate , ILocationUpdate } from '../models/LocationUpdate' ;
4+ import { toUTC , nowUTC } from '../utils/dateUtils' ;
45import {
56 LocationSyncPayload ,
67 OfflineLocationPoint ,
@@ -42,7 +43,7 @@ export class SyncService {
4243 driverId : string ,
4344 payload : LocationSyncPayload ,
4445 ) : Promise < LocationSyncAck > {
45- const processedAt = new Date ( ) . toISOString ( ) ;
46+ const processedAt = nowUTC ( ) . toISOString ( ) ;
4647
4748 // ── 1. Validate driverId ─────────────────────────────────────────────────
4849 if ( ! Types . ObjectId . isValid ( driverId ) ) {
@@ -87,7 +88,7 @@ export class SyncService {
8788 }
8889
8990 // ── 4. Fetch existing capturedAt values for this driver to detect dupes ──
90- const capturedAtDates = validPoints . map ( ( p ) => new Date ( p . capturedAt ) ) ;
91+ const capturedAtDates = validPoints . map ( ( p ) => toUTC ( p . capturedAt ) ) ;
9192
9293 const existingDocs = await LocationUpdate . find (
9394 {
@@ -97,7 +98,7 @@ export class SyncService {
9798 { capturedAt : 1 } ,
9899 ) . lean < Pick < ILocationUpdate , 'capturedAt' > [ ] > ( ) ;
99100
100- const existingSet = new Set < number > ( existingDocs . map ( ( d ) => new Date ( d . capturedAt ) . getTime ( ) ) ) ;
101+ const existingSet = new Set < number > ( existingDocs . map ( ( d ) => toUTC ( d . capturedAt ) . getTime ( ) ) ) ;
101102
102103 // ── 5. Build insertable documents, deduplicating within batch ─────────────
103104 const seenInBatch = new Set < number > ( ) ;
@@ -117,7 +118,7 @@ export class SyncService {
117118 driverId : driverObjectId ,
118119 deliveryId : point . deliveryId ? new Types . ObjectId ( point . deliveryId ) : undefined ,
119120 coordinates : { lat : point . lat , lng : point . lng } ,
120- capturedAt : new Date ( ts ) ,
121+ capturedAt : toUTC ( ts ) ,
121122 isOfflineSync : true ,
122123 status : 'pending' ,
123124 } ) ;
0 commit comments