@opencrvs/toolkit 1.9.8-rc.34c53bf → 1.9.8-rc.67435c3
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
|
@@ -3594,31 +3594,30 @@ ajv.addKeyword({
|
|
|
3594
3594
|
return locations.some((location) => location.id === locationIdInput);
|
|
3595
3595
|
}
|
|
3596
3596
|
});
|
|
3597
|
+
function isAgeValue(value) {
|
|
3598
|
+
return typeof value === "object" && value !== null && "age" in value && typeof value.age === "number";
|
|
3599
|
+
}
|
|
3597
3600
|
function validate(schema, data) {
|
|
3598
3601
|
const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
|
|
3599
3602
|
if ("$form" in data) {
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
const maybeAgeValue = AgeValue.safeParse(value);
|
|
3603
|
-
if (maybeAgeValue.success) {
|
|
3604
|
-
const age = maybeAgeValue.data.age;
|
|
3605
|
-
const maybeAsOfDate = DateValue.safeParse(
|
|
3606
|
-
data.$form[maybeAgeValue.data.asOfDateRef]
|
|
3607
|
-
);
|
|
3608
|
-
return [
|
|
3609
|
-
key,
|
|
3610
|
-
{
|
|
3611
|
-
age,
|
|
3612
|
-
dob: ageToDate(
|
|
3613
|
-
age,
|
|
3614
|
-
maybeAsOfDate.success ? maybeAsOfDate.data : data.$now
|
|
3615
|
-
)
|
|
3616
|
-
}
|
|
3617
|
-
];
|
|
3618
|
-
}
|
|
3603
|
+
const entries = Object.entries(data.$form).map(([key, value]) => {
|
|
3604
|
+
if (!isAgeValue(value)) {
|
|
3619
3605
|
return [key, value];
|
|
3620
|
-
}
|
|
3621
|
-
|
|
3606
|
+
}
|
|
3607
|
+
const age = value.age;
|
|
3608
|
+
const maybeAsOfDate = DateValue.safeParse(data.$form[value.asOfDateRef]);
|
|
3609
|
+
return [
|
|
3610
|
+
key,
|
|
3611
|
+
{
|
|
3612
|
+
age,
|
|
3613
|
+
dob: ageToDate(
|
|
3614
|
+
age,
|
|
3615
|
+
maybeAsOfDate.success ? maybeAsOfDate.data : data.$now
|
|
3616
|
+
)
|
|
3617
|
+
}
|
|
3618
|
+
];
|
|
3619
|
+
});
|
|
3620
|
+
data.$form = Object.fromEntries(entries);
|
|
3622
3621
|
}
|
|
3623
3622
|
const result = validator(data);
|
|
3624
3623
|
return result;
|