@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.
@@ -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
- data.$form = Object.fromEntries(
3598
- Object.entries(data.$form).map(([key, value]) => {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.9.7-rc.24a6eae",
3
+ "version": "1.9.7-rc.26c1876",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {