Skip to content

Commit

Permalink
fix: additional checks for data existence (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
turban committed Sep 9, 2020
1 parent 8347703 commit 6e9aa0a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/util/infrastructural.js
@@ -1,22 +1,24 @@
import { getInstance as getD2 } from 'd2';
import i18n from '@dhis2/d2-i18n';

// Loads settings and data for the infrastuctural dialog for org units

export const loadConfigurations = async () => {
const d2 = await getD2();
const api = d2.Api.getApi();
const [
infrastructuralPeriodType = {},
infrastructuralIndicators = {},
infrastructuralDataElements = {},
infraPeriodType,
infraIndicators,
infraDataElements,
] = await Promise.all([
api.get('configuration/infrastructuralPeriodType'),
api.get('configuration/infrastructuralIndicators'),
api.get('configuration/infrastructuralDataElements'),
]);
const periodType = infrastructuralPeriodType.id || 'Yearly';
const indicators = infrastructuralIndicators.indicators || [];
const dataElements = infrastructuralDataElements.dataElements || [];

const periodType =
(infraPeriodType && infraPeriodType.id) || i18n.t('Yearly');
const { indicators = [] } = infraIndicators || {};
const { dataElements = [] } = infraDataElements || {};

return {
periodType,
Expand Down

0 comments on commit 6e9aa0a

Please sign in to comment.