From aec3bdde4560f89cb8957a4012c3bfd648cf4f1c Mon Sep 17 00:00:00 2001 From: gqcorneby Date: Wed, 15 Jan 2025 18:37:24 +0800 Subject: [PATCH 1/2] used response stats as fallback if `bundleReport.stats` is undefined --- src/data/Dhis2Import.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/data/Dhis2Import.ts b/src/data/Dhis2Import.ts index 873911bb..34e3d546 100644 --- a/src/data/Dhis2Import.ts +++ b/src/data/Dhis2Import.ts @@ -70,11 +70,11 @@ export function processImportResponse(options: { rawResponse: importResult, }; } - + const trackerStats = bundleReport.stats || importResult.stats; const totalStats: SynchronizationStats = { type: "TOTAL", - imported: bundleReport.stats.created, - ...bundleReport.stats, + imported: trackerStats.created, + ...trackerStats, }; const eventStatsList = _(bundleReport.typeReportMap) From d64c4b13e8140b41277f228f4d2babf895eecedc Mon Sep 17 00:00:00 2001 From: gqcorneby Date: Mon, 20 Jan 2025 10:03:53 +0800 Subject: [PATCH 2/2] update `ImportReportResponse` nullable stats. Add null handling to use default stats w/ all zeros --- src/data/Dhis2Import.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/data/Dhis2Import.ts b/src/data/Dhis2Import.ts index 34e3d546..4bd4de37 100644 --- a/src/data/Dhis2Import.ts +++ b/src/data/Dhis2Import.ts @@ -36,14 +36,22 @@ export type ImportReportResponse = { } ]; }; - stats: ImportStats; + stats?: ImportStats; bundleReport?: { status: Status; - stats: ImportStats; + stats?: ImportStats; typeReportMap: TypeReportMap; }; }; +const defaultStats = { + created: 0, + deleted: 0, + ignored: 0, + updated: 0, + total: 0, +}; + export function processImportResponse(options: { title: string; model: string; @@ -70,7 +78,14 @@ export function processImportResponse(options: { rawResponse: importResult, }; } - const trackerStats = bundleReport.stats || importResult.stats; + const resStats = bundleReport.stats || importResult.stats; + + if( !resStats ) { + console.error(`No 'stats' found in import response.`, importResult); + } + + const trackerStats = resStats || defaultStats; + const totalStats: SynchronizationStats = { type: "TOTAL", imported: trackerStats.created,