Skip to content

Commit

Permalink
Merge pull request #118 from UN-OCHA/HPC-9094
Browse files Browse the repository at this point in the history
HPC-9094: Expand attachment and measurement codecs
  • Loading branch information
Pl217 authored Jun 6, 2023
2 parents 4b4e577 + e4ac4c9 commit e54ffbf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unocha/hpc-api-core",
"version": "5.2.0",
"version": "5.2.1",
"description": "Core libraries supporting HPC.Tools API Backend",
"license": "Apache-2.0",
"private": false,
Expand Down
1 change: 1 addition & 0 deletions src/db/models/attachmentPrototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const ATTACHMENT_PROTOTYPE_VALUE = t.intersection([
*/
max: t.union([t.number, t.string]),
metrics: FIELDS,
calculationMethod: t.array(t.string),
}),
]);

Expand Down
18 changes: 15 additions & 3 deletions src/db/models/json/indicatorsAndCaseloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const METRIC_WITH_VALUE = t.intersection([
* measurements incorrectly have string types. We should update all of these
* to be numbers when specified.
*/
value: t.union([t.number, t.null, t.literal('')]),
value: t.union([t.number, t.null, t.string]),
}),
]);

Expand Down Expand Up @@ -143,6 +143,7 @@ export const CASELOAD_VALUE = t.intersection([
}),
t.partial({
description: t.string,
name: t.string,
}),
]);

Expand Down Expand Up @@ -182,18 +183,29 @@ export const INDICATOR_VALUE = t.intersection([
}),
]),
measureFields: t.array(METRIC_DEFINITION),
calculationMethod: t.string,
}),
]),
}),
t.partial({
description: t.string,
name: t.string,
}),
]);

export type IndicatorValue = t.TypeOf<typeof INDICATOR_VALUE>;

/**
* measurement values have the same types as their respective caseload
* Measurement values have the same types as their respective caseload
* or indicator attachments
*/
export const MEASUREMENT_VALUE = t.union([INDICATOR_VALUE, CASELOAD_VALUE]);
export const MEASUREMENT_VALUE = t.union([
t.intersection([
INDICATOR_VALUE,
t.type({ attachmentType: t.literal('indicator') }),
]),
t.intersection([
CASELOAD_VALUE,
t.type({ attachmentType: t.literal('caseLoad') }),
]),
]);

0 comments on commit e54ffbf

Please sign in to comment.