From 7c8e18e41911dcd6747ba285aa66c712d08cccdd Mon Sep 17 00:00:00 2001 From: amit <1mitccc@gmail.com> Date: Fri, 20 Dec 2024 06:37:08 +0530 Subject: [PATCH] fix: onedrive: lastSyncTime returning null --- .../file/services/onedrive/index.ts | 19 ++++++++++++++++--- .../folder/services/onedrive/index.ts | 6 +++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/api/src/filestorage/file/services/onedrive/index.ts b/packages/api/src/filestorage/file/services/onedrive/index.ts index 4b26c7876..52f2c270a 100644 --- a/packages/api/src/filestorage/file/services/onedrive/index.ts +++ b/packages/api/src/filestorage/file/services/onedrive/index.ts @@ -258,16 +258,29 @@ export class OnedriveService implements IFileService { ); } - private async getLastSyncTime(connection: any) { + private async getLastSyncTime(connection: { + id_connection: string; + }): Promise { const lastSyncTime = await this.prisma.fs_files.findFirst({ where: { id_connection: connection.id_connection, }, orderBy: { - remote_modified_at: 'desc', + remote_modified_at: { + sort: 'desc', + nulls: 'last', + }, + }, + select: { + remote_modified_at: true, }, }); - return lastSyncTime?.remote_modified_at; + + this.logger.log( + `Last file sync time: ${lastSyncTime?.remote_modified_at}`, + 'onedrive files sync', + ); + return lastSyncTime?.remote_modified_at ?? null; } private async syncFolder( diff --git a/packages/api/src/filestorage/folder/services/onedrive/index.ts b/packages/api/src/filestorage/folder/services/onedrive/index.ts index c029f3ecf..c9f2cd32c 100644 --- a/packages/api/src/filestorage/folder/services/onedrive/index.ts +++ b/packages/api/src/filestorage/folder/services/onedrive/index.ts @@ -715,8 +715,12 @@ export class OnedriveService implements IFolderService { private async getLastSyncTime(connectionId: string): Promise { const lastSync = await this.prisma.fs_folders.findFirst({ where: { id_connection: connectionId }, - orderBy: { remote_modified_at: 'desc' }, + orderBy: { remote_modified_at: { sort: 'desc', nulls: 'last' } }, }); + this.logger.log( + `Last sync time: ${lastSync?.remote_modified_at}`, + 'onedrive folders sync', + ); return lastSync ? lastSync.remote_modified_at : null; }