@opencrvs/toolkit 1.9.7-rc.24a6eae → 1.9.7-rc.26c1876
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/events/index.js +20 -21
- package/package.json +1 -1
package/dist/events/index.js
CHANGED
|
@@ -3591,31 +3591,30 @@ ajv.addKeyword({
|
|
|
3591
3591
|
return locations.some((location) => location.id === locationIdInput);
|
|
3592
3592
|
}
|
|
3593
3593
|
});
|
|
3594
|
+
function isAgeValue(value) {
|
|
3595
|
+
return typeof value === "object" && value !== null && "age" in value && typeof value.age === "number";
|
|
3596
|
+
}
|
|
3594
3597
|
function validate(schema, data) {
|
|
3595
3598
|
const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
|
|
3596
3599
|
if ("$form" in data) {
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
const maybeAgeValue = AgeValue.safeParse(value);
|
|
3600
|
-
if (maybeAgeValue.success) {
|
|
3601
|
-
const age = maybeAgeValue.data.age;
|
|
3602
|
-
const maybeAsOfDate = DateValue.safeParse(
|
|
3603
|
-
data.$form[maybeAgeValue.data.asOfDateRef]
|
|
3604
|
-
);
|
|
3605
|
-
return [
|
|
3606
|
-
key,
|
|
3607
|
-
{
|
|
3608
|
-
age,
|
|
3609
|
-
dob: ageToDate(
|
|
3610
|
-
age,
|
|
3611
|
-
maybeAsOfDate.success ? maybeAsOfDate.data : data.$now
|
|
3612
|
-
)
|
|
3613
|
-
}
|
|
3614
|
-
];
|
|
3615
|
-
}
|
|
3600
|
+
const entries = Object.entries(data.$form).map(([key, value]) => {
|
|
3601
|
+
if (!isAgeValue(value)) {
|
|
3616
3602
|
return [key, value];
|
|
3617
|
-
}
|
|
3618
|
-
|
|
3603
|
+
}
|
|
3604
|
+
const age = value.age;
|
|
3605
|
+
const maybeAsOfDate = DateValue.safeParse(data.$form[value.asOfDateRef]);
|
|
3606
|
+
return [
|
|
3607
|
+
key,
|
|
3608
|
+
{
|
|
3609
|
+
age,
|
|
3610
|
+
dob: ageToDate(
|
|
3611
|
+
age,
|
|
3612
|
+
maybeAsOfDate.success ? maybeAsOfDate.data : data.$now
|
|
3613
|
+
)
|
|
3614
|
+
}
|
|
3615
|
+
];
|
|
3616
|
+
});
|
|
3617
|
+
data.$form = Object.fromEntries(entries);
|
|
3619
3618
|
}
|
|
3620
3619
|
const result = validator(data);
|
|
3621
3620
|
return result;
|