Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

used response stats as fallback if bundleReport.stats is undefined #341

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/data/Dhis2Import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -70,11 +78,18 @@ export function processImportResponse(options: {
rawResponse: importResult,
};
}
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: bundleReport.stats.created,
...bundleReport.stats,
imported: trackerStats.created,
...trackerStats,
tokland marked this conversation as resolved.
Show resolved Hide resolved
};

const eventStatsList = _(bundleReport.typeReportMap)
Expand Down