nox-validation 1.7.7 → 1.7.9
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/lib/helpers.js +56 -56
- package/lib/validate.js +82 -80
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -7,7 +7,7 @@ const getAllFields = (obj, parentPath = "") => {
|
|
|
7
7
|
return obj[key].flatMap((item, index) =>
|
|
8
8
|
typeof item === "object" && item !== null
|
|
9
9
|
? getAllFields(item, `${path}[${index}]`)
|
|
10
|
-
: `${path}[${index}]
|
|
10
|
+
: `${path}[${index}]`,
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
return typeof obj[key] === "object" &&
|
|
@@ -317,7 +317,7 @@ const generateField = (
|
|
|
317
317
|
required: false,
|
|
318
318
|
nullable: false,
|
|
319
319
|
hidden: false,
|
|
320
|
-
}
|
|
320
|
+
},
|
|
321
321
|
) => {
|
|
322
322
|
const { staticType = null, parentInterface = null } = meta;
|
|
323
323
|
childrenFields = childrenFields?.map((child) => {
|
|
@@ -360,13 +360,13 @@ const createChildrenFieldsFiles = (key) => {
|
|
|
360
360
|
"existing",
|
|
361
361
|
`${key}.existing`,
|
|
362
362
|
constants.types.OBJECT_ID,
|
|
363
|
-
constants.types.ARRAY
|
|
363
|
+
constants.types.ARRAY,
|
|
364
364
|
);
|
|
365
365
|
const deleteField = generateField(
|
|
366
366
|
"delete",
|
|
367
367
|
`${key}.delete`,
|
|
368
368
|
constants.types.OBJECT_ID,
|
|
369
|
-
constants.types.ARRAY
|
|
369
|
+
constants.types.ARRAY,
|
|
370
370
|
);
|
|
371
371
|
return [existingField, deleteField];
|
|
372
372
|
};
|
|
@@ -374,7 +374,7 @@ const createChildrenFieldsFiles = (key) => {
|
|
|
374
374
|
const generateRelationalFieldV1 = (
|
|
375
375
|
key = "",
|
|
376
376
|
collectionFields = [],
|
|
377
|
-
relationType
|
|
377
|
+
relationType,
|
|
378
378
|
) => {
|
|
379
379
|
if (relationType === constants.interfaces.MANY_TO_ANY) {
|
|
380
380
|
return [
|
|
@@ -382,19 +382,19 @@ const generateRelationalFieldV1 = (
|
|
|
382
382
|
"collection",
|
|
383
383
|
`${key}.collection`,
|
|
384
384
|
constants.types.STRING,
|
|
385
|
-
constants.types.STRING
|
|
385
|
+
constants.types.STRING,
|
|
386
386
|
),
|
|
387
387
|
generateField(
|
|
388
388
|
"sort",
|
|
389
389
|
`${key}.sort`,
|
|
390
390
|
constants.types.NUMBER,
|
|
391
|
-
constants.types.NUMBER
|
|
391
|
+
constants.types.NUMBER,
|
|
392
392
|
),
|
|
393
393
|
generateField(
|
|
394
394
|
"item",
|
|
395
395
|
`${key}.item`,
|
|
396
396
|
constants.types.OBJECT_ID,
|
|
397
|
-
constants.types.OBJECT_ID
|
|
397
|
+
constants.types.OBJECT_ID,
|
|
398
398
|
),
|
|
399
399
|
];
|
|
400
400
|
} else {
|
|
@@ -405,7 +405,7 @@ const generateRelationalFieldV1 = (
|
|
|
405
405
|
const generateRelationalField = (
|
|
406
406
|
key = "",
|
|
407
407
|
collectionFields = [],
|
|
408
|
-
relationType
|
|
408
|
+
relationType,
|
|
409
409
|
) => {
|
|
410
410
|
if (relationType === constants.interfaces.MANY_TO_ANY) {
|
|
411
411
|
const collection_id_meta = {
|
|
@@ -421,20 +421,20 @@ const generateRelationalField = (
|
|
|
421
421
|
[],
|
|
422
422
|
"none",
|
|
423
423
|
[],
|
|
424
|
-
{ staticType: "existing", parentInterface: relationType }
|
|
424
|
+
{ staticType: "existing", parentInterface: relationType },
|
|
425
425
|
);
|
|
426
426
|
existingField.children = [
|
|
427
427
|
generateField(
|
|
428
428
|
"collection",
|
|
429
429
|
`${key}.existing.collection`,
|
|
430
430
|
constants.types.STRING,
|
|
431
|
-
constants.types.STRING
|
|
431
|
+
constants.types.STRING,
|
|
432
432
|
),
|
|
433
433
|
generateField(
|
|
434
434
|
"sort",
|
|
435
435
|
`${key}.existing.sort`,
|
|
436
436
|
constants.types.NUMBER,
|
|
437
|
-
constants.types.NUMBER
|
|
437
|
+
constants.types.NUMBER,
|
|
438
438
|
),
|
|
439
439
|
generateField(
|
|
440
440
|
"collection_id",
|
|
@@ -444,13 +444,13 @@ const generateRelationalField = (
|
|
|
444
444
|
[],
|
|
445
445
|
"none",
|
|
446
446
|
[],
|
|
447
|
-
collection_id_meta
|
|
447
|
+
collection_id_meta,
|
|
448
448
|
),
|
|
449
449
|
generateField(
|
|
450
450
|
"item",
|
|
451
451
|
`${key}.existing.item`,
|
|
452
452
|
constants.types.OBJECT_ID,
|
|
453
|
-
constants.types.OBJECT_ID
|
|
453
|
+
constants.types.OBJECT_ID,
|
|
454
454
|
),
|
|
455
455
|
];
|
|
456
456
|
const deleteField = generateField(
|
|
@@ -461,20 +461,20 @@ const generateRelationalField = (
|
|
|
461
461
|
[],
|
|
462
462
|
"none",
|
|
463
463
|
[],
|
|
464
|
-
{ staticType: "delete", parentInterface: relationType }
|
|
464
|
+
{ staticType: "delete", parentInterface: relationType },
|
|
465
465
|
);
|
|
466
466
|
deleteField.children = [
|
|
467
467
|
generateField(
|
|
468
468
|
"collection",
|
|
469
469
|
`${key}.delete.collection`,
|
|
470
470
|
constants.types.STRING,
|
|
471
|
-
constants.types.STRING
|
|
471
|
+
constants.types.STRING,
|
|
472
472
|
),
|
|
473
473
|
generateField(
|
|
474
474
|
"sort",
|
|
475
475
|
`${key}.delete.sort`,
|
|
476
476
|
constants.types.NUMBER,
|
|
477
|
-
constants.types.NUMBER
|
|
477
|
+
constants.types.NUMBER,
|
|
478
478
|
),
|
|
479
479
|
generateField(
|
|
480
480
|
"collection_id",
|
|
@@ -484,13 +484,13 @@ const generateRelationalField = (
|
|
|
484
484
|
[],
|
|
485
485
|
"none",
|
|
486
486
|
[],
|
|
487
|
-
collection_id_meta
|
|
487
|
+
collection_id_meta,
|
|
488
488
|
),
|
|
489
489
|
generateField(
|
|
490
490
|
"item",
|
|
491
491
|
`${key}.delete.item`,
|
|
492
492
|
constants.types.OBJECT_ID,
|
|
493
|
-
constants.types.OBJECT_ID
|
|
493
|
+
constants.types.OBJECT_ID,
|
|
494
494
|
),
|
|
495
495
|
];
|
|
496
496
|
const createField = generateField(
|
|
@@ -502,14 +502,14 @@ const generateRelationalField = (
|
|
|
502
502
|
[],
|
|
503
503
|
"none",
|
|
504
504
|
[],
|
|
505
|
-
{ staticType: "create", parentInterface: relationType }
|
|
505
|
+
{ staticType: "create", parentInterface: relationType },
|
|
506
506
|
);
|
|
507
507
|
createField.children = [
|
|
508
508
|
generateField(
|
|
509
509
|
"collection",
|
|
510
510
|
`${key}.create.collection`,
|
|
511
511
|
constants.types.STRING,
|
|
512
|
-
constants.types.STRING
|
|
512
|
+
constants.types.STRING,
|
|
513
513
|
),
|
|
514
514
|
generateField(
|
|
515
515
|
"collection_id",
|
|
@@ -519,13 +519,13 @@ const generateRelationalField = (
|
|
|
519
519
|
[],
|
|
520
520
|
"none",
|
|
521
521
|
[],
|
|
522
|
-
collection_id_meta
|
|
522
|
+
collection_id_meta,
|
|
523
523
|
),
|
|
524
524
|
generateField(
|
|
525
525
|
"sort",
|
|
526
526
|
`${key}.create.sort`,
|
|
527
527
|
constants.types.NUMBER,
|
|
528
|
-
constants.types.NUMBER
|
|
528
|
+
constants.types.NUMBER,
|
|
529
529
|
),
|
|
530
530
|
generateField(
|
|
531
531
|
"item",
|
|
@@ -535,7 +535,7 @@ const generateRelationalField = (
|
|
|
535
535
|
[...collectionFields],
|
|
536
536
|
"none",
|
|
537
537
|
[constants.types.OBJECT_ID],
|
|
538
|
-
{ ...collection_id_meta, is_m2a_item: true }
|
|
538
|
+
{ ...collection_id_meta, is_m2a_item: true },
|
|
539
539
|
),
|
|
540
540
|
];
|
|
541
541
|
const updateField = generateField(
|
|
@@ -547,14 +547,14 @@ const generateRelationalField = (
|
|
|
547
547
|
[],
|
|
548
548
|
"none",
|
|
549
549
|
[],
|
|
550
|
-
{ staticType: "update", parentInterface: relationType }
|
|
550
|
+
{ staticType: "update", parentInterface: relationType },
|
|
551
551
|
);
|
|
552
552
|
updateField.children = [
|
|
553
553
|
generateField(
|
|
554
554
|
"collection",
|
|
555
555
|
`${key}.update.collection`,
|
|
556
556
|
constants.types.STRING,
|
|
557
|
-
constants.types.STRING
|
|
557
|
+
constants.types.STRING,
|
|
558
558
|
),
|
|
559
559
|
generateField(
|
|
560
560
|
"collection_id",
|
|
@@ -564,13 +564,13 @@ const generateRelationalField = (
|
|
|
564
564
|
[],
|
|
565
565
|
"none",
|
|
566
566
|
[],
|
|
567
|
-
collection_id_meta
|
|
567
|
+
collection_id_meta,
|
|
568
568
|
),
|
|
569
569
|
generateField(
|
|
570
570
|
"sort",
|
|
571
571
|
`${key}.update.sort`,
|
|
572
572
|
constants.types.NUMBER,
|
|
573
|
-
constants.types.NUMBER
|
|
573
|
+
constants.types.NUMBER,
|
|
574
574
|
),
|
|
575
575
|
generateField(
|
|
576
576
|
"item",
|
|
@@ -580,7 +580,7 @@ const generateRelationalField = (
|
|
|
580
580
|
[...collectionFields],
|
|
581
581
|
"none",
|
|
582
582
|
[constants.types.OBJECT_ID],
|
|
583
|
-
{ ...collection_id_meta, is_m2a_item: true }
|
|
583
|
+
{ ...collection_id_meta, is_m2a_item: true },
|
|
584
584
|
),
|
|
585
585
|
];
|
|
586
586
|
return [existingField, deleteField, createField, updateField];
|
|
@@ -594,7 +594,7 @@ const generateRelationalField = (
|
|
|
594
594
|
[],
|
|
595
595
|
"none",
|
|
596
596
|
[],
|
|
597
|
-
{ staticType: "existing", parentInterface: relationType }
|
|
597
|
+
{ staticType: "existing", parentInterface: relationType },
|
|
598
598
|
),
|
|
599
599
|
generateField(
|
|
600
600
|
"delete",
|
|
@@ -604,7 +604,7 @@ const generateRelationalField = (
|
|
|
604
604
|
[],
|
|
605
605
|
"none",
|
|
606
606
|
[],
|
|
607
|
-
{ staticType: "delete", parentInterface: relationType }
|
|
607
|
+
{ staticType: "delete", parentInterface: relationType },
|
|
608
608
|
),
|
|
609
609
|
generateField(
|
|
610
610
|
"create",
|
|
@@ -614,7 +614,7 @@ const generateRelationalField = (
|
|
|
614
614
|
collectionFields,
|
|
615
615
|
"none",
|
|
616
616
|
[],
|
|
617
|
-
{ staticType: "create", parentInterface: relationType }
|
|
617
|
+
{ staticType: "create", parentInterface: relationType },
|
|
618
618
|
),
|
|
619
619
|
generateField(
|
|
620
620
|
"update",
|
|
@@ -624,7 +624,7 @@ const generateRelationalField = (
|
|
|
624
624
|
collectionFields,
|
|
625
625
|
"none",
|
|
626
626
|
[],
|
|
627
|
-
{ staticType: "update", parentInterface: relationType }
|
|
627
|
+
{ staticType: "update", parentInterface: relationType },
|
|
628
628
|
),
|
|
629
629
|
];
|
|
630
630
|
}
|
|
@@ -657,7 +657,7 @@ const getForeignCollectionDetails = ({
|
|
|
657
657
|
|
|
658
658
|
if (isListInterface) {
|
|
659
659
|
const mainTable = relations.find(
|
|
660
|
-
(d) => d.one_collection_id === collection && d.one_field_id === field
|
|
660
|
+
(d) => d.one_collection_id === collection && d.one_field_id === field,
|
|
661
661
|
);
|
|
662
662
|
if (!mainTable) return {};
|
|
663
663
|
|
|
@@ -666,7 +666,7 @@ const getForeignCollectionDetails = ({
|
|
|
666
666
|
? relations.find(
|
|
667
667
|
(d) =>
|
|
668
668
|
d.many_collection === mainTable.many_collection &&
|
|
669
|
-
d.junction_field === mainTable.many_field
|
|
669
|
+
d.junction_field === mainTable.many_field,
|
|
670
670
|
)
|
|
671
671
|
: [];
|
|
672
672
|
|
|
@@ -678,15 +678,15 @@ const getForeignCollectionDetails = ({
|
|
|
678
678
|
iFace === constants.interfaces.MANY_TO_MANY
|
|
679
679
|
? relational?.one_collection_id
|
|
680
680
|
: iFace === constants.interfaces.MANY_TO_ANY
|
|
681
|
-
|
|
682
|
-
|
|
681
|
+
? relational?.one_allowed_collections_id
|
|
682
|
+
: mainTable.many_collection_id,
|
|
683
683
|
foreign_field:
|
|
684
684
|
iFace === constants.interfaces.MANY_TO_MANY ||
|
|
685
685
|
iFace === constants.interfaces.TRANSLATIONS
|
|
686
686
|
? "_id"
|
|
687
687
|
: iFace === constants.interfaces.MANY_TO_ANY
|
|
688
|
-
|
|
689
|
-
|
|
688
|
+
? "Primary Key"
|
|
689
|
+
: mainTable.many_field_id,
|
|
690
690
|
...(isJunction && {
|
|
691
691
|
junction_collection: relational?.many_collection_id,
|
|
692
692
|
junction_field_this: relational?.junction_field,
|
|
@@ -719,7 +719,7 @@ const getForeignCollectionDetails = ({
|
|
|
719
719
|
|
|
720
720
|
if (isSingleRelation) {
|
|
721
721
|
const mainTable = relations.find(
|
|
722
|
-
(d) => d.many_collection_id === collection && d.many_field_id === field
|
|
722
|
+
(d) => d.many_collection_id === collection && d.many_field_id === field,
|
|
723
723
|
);
|
|
724
724
|
if (!mainTable) return {};
|
|
725
725
|
|
|
@@ -752,7 +752,7 @@ const getCachedFields = (relationDetail, relational_fields) => {
|
|
|
752
752
|
return getField(relationDetail.foreign_collection);
|
|
753
753
|
} else {
|
|
754
754
|
return relationDetail.foreign_collection.flatMap((schemaId) =>
|
|
755
|
-
getField(schemaId)
|
|
755
|
+
getField(schemaId),
|
|
756
756
|
);
|
|
757
757
|
}
|
|
758
758
|
};
|
|
@@ -773,7 +773,7 @@ const getChildFields = (
|
|
|
773
773
|
allFields,
|
|
774
774
|
relational_fields,
|
|
775
775
|
isTranslation,
|
|
776
|
-
name
|
|
776
|
+
name,
|
|
777
777
|
) => {
|
|
778
778
|
let key = isTranslation
|
|
779
779
|
? [
|
|
@@ -792,7 +792,7 @@ const getChildFields = (
|
|
|
792
792
|
return getCachedOrFetchFields(key, allFields, relational_fields);
|
|
793
793
|
} else {
|
|
794
794
|
return key.flatMap((schemaId) =>
|
|
795
|
-
getCachedOrFetchFields(schemaId, allFields, relational_fields)
|
|
795
|
+
getCachedOrFetchFields(schemaId, allFields, relational_fields),
|
|
796
796
|
);
|
|
797
797
|
}
|
|
798
798
|
};
|
|
@@ -826,7 +826,7 @@ const buildNestedStructure = ({
|
|
|
826
826
|
const nodeMap = new Map();
|
|
827
827
|
|
|
828
828
|
schemaFields.sort(
|
|
829
|
-
(a, b) => a.path.split(".").length - b.path.split(".").length
|
|
829
|
+
(a, b) => a.path.split(".").length - b.path.split(".").length,
|
|
830
830
|
);
|
|
831
831
|
|
|
832
832
|
schemaFields.forEach((item) => {
|
|
@@ -863,7 +863,7 @@ const buildNestedStructure = ({
|
|
|
863
863
|
allFields,
|
|
864
864
|
relational_fields,
|
|
865
865
|
item?.meta?.interface === constants.interfaces.TRANSLATIONS,
|
|
866
|
-
key
|
|
866
|
+
key,
|
|
867
867
|
);
|
|
868
868
|
} else {
|
|
869
869
|
childFields = getCachedFields(relationDetail, relational_fields);
|
|
@@ -914,7 +914,7 @@ const buildNestedStructure = ({
|
|
|
914
914
|
}
|
|
915
915
|
|
|
916
916
|
const isArray =
|
|
917
|
-
item.type === item?.schema_definition
|
|
917
|
+
item.type === item?.schema_definition?.type &&
|
|
918
918
|
item.type === constants.types.ARRAY;
|
|
919
919
|
|
|
920
920
|
let children = [];
|
|
@@ -998,7 +998,7 @@ const buildNestedStructure = ({
|
|
|
998
998
|
item?.meta,
|
|
999
999
|
item?.meta?.validations?.validation_msg?.trim() === ""
|
|
1000
1000
|
? null
|
|
1001
|
-
: item?.meta?.validations?.validation_msg
|
|
1001
|
+
: item?.meta?.validations?.validation_msg,
|
|
1002
1002
|
),
|
|
1003
1003
|
custom_error_message:
|
|
1004
1004
|
item?.meta?.validations?.validation_msg?.trim() === ""
|
|
@@ -1033,7 +1033,7 @@ const buildNestedStructure = ({
|
|
|
1033
1033
|
return nodes.map(({ children, ...node }) =>
|
|
1034
1034
|
children && children?.length
|
|
1035
1035
|
? { ...node, children: removeEmptyChildren(children) }
|
|
1036
|
-
: node
|
|
1036
|
+
: node,
|
|
1037
1037
|
);
|
|
1038
1038
|
};
|
|
1039
1039
|
|
|
@@ -1066,7 +1066,7 @@ const findDisallowedKeys = (formData, structure, maxLevel) => {
|
|
|
1066
1066
|
const keyLevel = keyParts.length;
|
|
1067
1067
|
const levelParent = keyParts.slice(0, maxLevel - 1).join(".");
|
|
1068
1068
|
return !validKeys.has(
|
|
1069
|
-
normalizeKey(keyLevel > maxLevel ? levelParent : key)
|
|
1069
|
+
normalizeKey(keyLevel > maxLevel ? levelParent : key),
|
|
1070
1070
|
);
|
|
1071
1071
|
});
|
|
1072
1072
|
};
|
|
@@ -1359,7 +1359,7 @@ const getDefaultValues = (tree) => {
|
|
|
1359
1359
|
setValue(
|
|
1360
1360
|
defaultValues,
|
|
1361
1361
|
cleanKey,
|
|
1362
|
-
children?.length ? getDefaultValues(children) : {}
|
|
1362
|
+
children?.length ? getDefaultValues(children) : {},
|
|
1363
1363
|
);
|
|
1364
1364
|
} else if (type === "Array") {
|
|
1365
1365
|
if (array_type === "String" || array_type === "Number") {
|
|
@@ -1369,7 +1369,7 @@ const getDefaultValues = (tree) => {
|
|
|
1369
1369
|
setValue(
|
|
1370
1370
|
defaultValues,
|
|
1371
1371
|
cleanKey,
|
|
1372
|
-
children?.length ? [getDefaultValues(children)] : []
|
|
1372
|
+
children?.length ? [getDefaultValues(children)] : [],
|
|
1373
1373
|
);
|
|
1374
1374
|
}
|
|
1375
1375
|
} else {
|
|
@@ -1382,7 +1382,7 @@ const getDefaultValues = (tree) => {
|
|
|
1382
1382
|
|
|
1383
1383
|
const extractRelationalParents = (path) => {
|
|
1384
1384
|
const match = path?.match(
|
|
1385
|
-
/^([^.\[\]]+)\.(create|update|delete|existing)\[(\d+)\](?:\.(.*))
|
|
1385
|
+
/^([^.\[\]]+)\.(create|update|delete|existing)\[(\d+)\](?:\.(.*))?/,
|
|
1386
1386
|
);
|
|
1387
1387
|
if (match) {
|
|
1388
1388
|
const secondParent = match[1];
|
|
@@ -1438,7 +1438,7 @@ const getSelectedNodes = ({
|
|
|
1438
1438
|
}
|
|
1439
1439
|
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
1440
1440
|
updatedNode.children = node.children.map((c) =>
|
|
1441
|
-
updateChildKeys(c, parentKey, newParentKey)
|
|
1441
|
+
updateChildKeys(c, parentKey, newParentKey),
|
|
1442
1442
|
);
|
|
1443
1443
|
}
|
|
1444
1444
|
return updatedNode;
|
|
@@ -1473,11 +1473,11 @@ const getSelectedNodes = ({
|
|
|
1473
1473
|
if (currentNode?.meta?.staticType) {
|
|
1474
1474
|
currentNode.key = addIndexToStaticType(
|
|
1475
1475
|
currentNode.key,
|
|
1476
|
-
currentNode?.meta?.staticType
|
|
1476
|
+
currentNode?.meta?.staticType,
|
|
1477
1477
|
);
|
|
1478
1478
|
currentNode.value = addIndexToStaticType(
|
|
1479
1479
|
currentNode.value,
|
|
1480
|
-
currentNode?.meta?.staticType
|
|
1480
|
+
currentNode?.meta?.staticType,
|
|
1481
1481
|
);
|
|
1482
1482
|
}
|
|
1483
1483
|
|
|
@@ -1567,7 +1567,7 @@ const formatDate = ({
|
|
|
1567
1567
|
|
|
1568
1568
|
const { year, month, day, hour, minute, second, dayPeriod } = getParts(
|
|
1569
1569
|
date,
|
|
1570
|
-
timeZone
|
|
1570
|
+
timeZone,
|
|
1571
1571
|
);
|
|
1572
1572
|
|
|
1573
1573
|
let hour24 = Number(hour);
|
package/lib/validate.js
CHANGED
|
@@ -133,7 +133,7 @@ const handleMinMaxValidation = (
|
|
|
133
133
|
addError,
|
|
134
134
|
currentPath,
|
|
135
135
|
error_messages,
|
|
136
|
-
custom_message
|
|
136
|
+
custom_message,
|
|
137
137
|
) => {
|
|
138
138
|
let message = "";
|
|
139
139
|
const fieldLabel = formatLabel(field.display_label);
|
|
@@ -186,7 +186,7 @@ const handleMinMaxValidation = (
|
|
|
186
186
|
addError(
|
|
187
187
|
currentPath,
|
|
188
188
|
{ label: fieldLabel, fieldPath: currentPath, description: "", message },
|
|
189
|
-
field
|
|
189
|
+
field,
|
|
190
190
|
);
|
|
191
191
|
}
|
|
192
192
|
};
|
|
@@ -233,13 +233,13 @@ const isEmptyRelational = ({
|
|
|
233
233
|
? existingValue.length === 0
|
|
234
234
|
? []
|
|
235
235
|
: typeof existingValue[0] === "string"
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
? existingValue
|
|
237
|
+
: existingValue.map((item) => item._id)
|
|
238
238
|
: typeof existingValue === "string"
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
239
|
+
? [existingValue]
|
|
240
|
+
: existingValue && typeof existingValue === "object"
|
|
241
|
+
? [existingValue._id]
|
|
242
|
+
: [];
|
|
243
243
|
all = Array.isArray(all) ? all?.filter(Boolean) : all;
|
|
244
244
|
switch (interface) {
|
|
245
245
|
case constants.interfaces.FILE:
|
|
@@ -282,7 +282,7 @@ const validateMetaRules = (
|
|
|
282
282
|
language_codes = [],
|
|
283
283
|
existingForm = {},
|
|
284
284
|
getNodes = true,
|
|
285
|
-
translatedPath = null
|
|
285
|
+
translatedPath = null,
|
|
286
286
|
) => {
|
|
287
287
|
const fieldValue = providedValue;
|
|
288
288
|
|
|
@@ -311,11 +311,12 @@ const validateMetaRules = (
|
|
|
311
311
|
|
|
312
312
|
if (
|
|
313
313
|
choices.includes(field?.meta?.interface) &&
|
|
314
|
-
(!options?.choices || !options?.choices?.length > 0)
|
|
314
|
+
(!options?.choices || !options?.choices?.length > 0) &&
|
|
315
|
+
required
|
|
315
316
|
) {
|
|
316
317
|
const message = error_messages.ADD_CHOICE.replace(
|
|
317
318
|
`{field}`,
|
|
318
|
-
formatLabel(field.display_label)
|
|
319
|
+
formatLabel(field.display_label),
|
|
319
320
|
);
|
|
320
321
|
addError(
|
|
321
322
|
currentPath,
|
|
@@ -325,7 +326,7 @@ const validateMetaRules = (
|
|
|
325
326
|
description: "",
|
|
326
327
|
message,
|
|
327
328
|
},
|
|
328
|
-
field
|
|
329
|
+
field,
|
|
329
330
|
);
|
|
330
331
|
}
|
|
331
332
|
|
|
@@ -347,7 +348,7 @@ const validateMetaRules = (
|
|
|
347
348
|
) {
|
|
348
349
|
const message = error_messages.NOT_EMPTY.replace(
|
|
349
350
|
`{field}`,
|
|
350
|
-
formatLabel(field.display_label)
|
|
351
|
+
formatLabel(field.display_label),
|
|
351
352
|
);
|
|
352
353
|
addError(
|
|
353
354
|
currentPath,
|
|
@@ -357,7 +358,7 @@ const validateMetaRules = (
|
|
|
357
358
|
description: "",
|
|
358
359
|
message,
|
|
359
360
|
},
|
|
360
|
-
field
|
|
361
|
+
field,
|
|
361
362
|
);
|
|
362
363
|
}
|
|
363
364
|
|
|
@@ -376,7 +377,7 @@ const validateMetaRules = (
|
|
|
376
377
|
?.replace(".create", "")
|
|
377
378
|
?.replace(".update", "")
|
|
378
379
|
?.replace(".existing", "")
|
|
379
|
-
?.replace(".delete", "")
|
|
380
|
+
?.replace(".delete", ""),
|
|
380
381
|
), // TODO: Need to Generate Form Path Without create, update, existing, delete
|
|
381
382
|
})
|
|
382
383
|
: true;
|
|
@@ -398,11 +399,11 @@ const validateMetaRules = (
|
|
|
398
399
|
const message = field?.meta?.required
|
|
399
400
|
? error_messages.REQUIRED.replace(
|
|
400
401
|
`{field}`,
|
|
401
|
-
formatLabel(field.display_label)
|
|
402
|
+
formatLabel(field.display_label),
|
|
402
403
|
)
|
|
403
404
|
: error_messages.NOT_EMPTY.replace(
|
|
404
405
|
`{field}`,
|
|
405
|
-
formatLabel(field.display_label)
|
|
406
|
+
formatLabel(field.display_label),
|
|
406
407
|
);
|
|
407
408
|
|
|
408
409
|
addError(
|
|
@@ -421,14 +422,14 @@ const validateMetaRules = (
|
|
|
421
422
|
description: "",
|
|
422
423
|
message,
|
|
423
424
|
},
|
|
424
|
-
field
|
|
425
|
+
field,
|
|
425
426
|
);
|
|
426
427
|
}
|
|
427
428
|
|
|
428
429
|
if (!nullable && fieldValue === null) {
|
|
429
430
|
const message = error_messages.NOT_EMPTY.replace(
|
|
430
431
|
`{field}`,
|
|
431
|
-
formatLabel(field.display_label)
|
|
432
|
+
formatLabel(field.display_label),
|
|
432
433
|
);
|
|
433
434
|
addError(
|
|
434
435
|
currentPath,
|
|
@@ -438,7 +439,7 @@ const validateMetaRules = (
|
|
|
438
439
|
description: "",
|
|
439
440
|
message,
|
|
440
441
|
},
|
|
441
|
-
field
|
|
442
|
+
field,
|
|
442
443
|
);
|
|
443
444
|
}
|
|
444
445
|
|
|
@@ -594,7 +595,7 @@ const validateMetaRules = (
|
|
|
594
595
|
node?.value?.includes("create[0]")
|
|
595
596
|
) {
|
|
596
597
|
langPath = rebuildFullPath(node.value, fPath, (path) =>
|
|
597
|
-
path.replace(/create\[0\]\./, `create[${index}].`)
|
|
598
|
+
path.replace(/create\[0\]\./, `create[${index}].`),
|
|
598
599
|
);
|
|
599
600
|
transformedPath = rebuildFullPath(node.value, fPath, (path) => {
|
|
600
601
|
const newPath = path
|
|
@@ -608,7 +609,7 @@ const validateMetaRules = (
|
|
|
608
609
|
});
|
|
609
610
|
|
|
610
611
|
transformedPath = rebuildFullPath(node.value, fPath, (path) =>
|
|
611
|
-
path.replace(/\[0\]\./, `.${lang}.`)?.replace("create", "")
|
|
612
|
+
path.replace(/\[0\]\./, `.${lang}.`)?.replace("create", ""),
|
|
612
613
|
);
|
|
613
614
|
}
|
|
614
615
|
|
|
@@ -619,7 +620,7 @@ const validateMetaRules = (
|
|
|
619
620
|
} else {
|
|
620
621
|
const singlePath = fPath.replace(
|
|
621
622
|
"create.",
|
|
622
|
-
isTranslationNode ? "create[lang_code]." : "create[0]."
|
|
623
|
+
isTranslationNode ? "create[lang_code]." : "create[0].",
|
|
623
624
|
);
|
|
624
625
|
if (
|
|
625
626
|
constants.interfaces.ITEMS === field?.meta?.interface
|
|
@@ -635,14 +636,14 @@ const validateMetaRules = (
|
|
|
635
636
|
const validType =
|
|
636
637
|
field?.alternateType?.length > 0
|
|
637
638
|
? [field.type, ...field?.alternateType].some((type) =>
|
|
638
|
-
typeChecks[type](fieldValue)
|
|
639
|
+
typeChecks[type](fieldValue),
|
|
639
640
|
)
|
|
640
641
|
: typeChecks[field.type](fieldValue, { key: currentPath, updateValue });
|
|
641
642
|
|
|
642
643
|
if (!isEmpty(fieldValue) && !validType) {
|
|
643
644
|
const message = error_messages.INVALID_TYPE.replace(
|
|
644
645
|
`{field}`,
|
|
645
|
-
formatLabel(field.display_label)
|
|
646
|
+
formatLabel(field.display_label),
|
|
646
647
|
).replace(`{type}`, field?.type);
|
|
647
648
|
addError(
|
|
648
649
|
currentPath,
|
|
@@ -652,7 +653,7 @@ const validateMetaRules = (
|
|
|
652
653
|
description: "",
|
|
653
654
|
message,
|
|
654
655
|
},
|
|
655
|
-
field
|
|
656
|
+
field,
|
|
656
657
|
);
|
|
657
658
|
}
|
|
658
659
|
};
|
|
@@ -664,7 +665,7 @@ const handleRegexValidation = (
|
|
|
664
665
|
addError,
|
|
665
666
|
currentPath,
|
|
666
667
|
error_messages,
|
|
667
|
-
custom_message
|
|
668
|
+
custom_message,
|
|
668
669
|
) => {
|
|
669
670
|
function escapeRegex(str) {
|
|
670
671
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -751,7 +752,7 @@ const handleRegexValidation = (
|
|
|
751
752
|
addError(
|
|
752
753
|
currentPath,
|
|
753
754
|
{ label: fieldLabel, fieldPath: currentPath, description: "", message },
|
|
754
|
-
field
|
|
755
|
+
field,
|
|
755
756
|
);
|
|
756
757
|
}
|
|
757
758
|
};
|
|
@@ -765,7 +766,7 @@ const validateOperatorRule = (
|
|
|
765
766
|
formData,
|
|
766
767
|
error_messages,
|
|
767
768
|
custom_message,
|
|
768
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
769
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
769
770
|
) => {
|
|
770
771
|
const { isFieldCompare = false } = rule?.options ?? {};
|
|
771
772
|
let valid = false;
|
|
@@ -822,7 +823,7 @@ const validateOperatorRule = (
|
|
|
822
823
|
return Date.UTC(
|
|
823
824
|
date.getUTCFullYear(),
|
|
824
825
|
date.getUTCMonth(),
|
|
825
|
-
date.getUTCDate()
|
|
826
|
+
date.getUTCDate(),
|
|
826
827
|
);
|
|
827
828
|
};
|
|
828
829
|
|
|
@@ -840,7 +841,7 @@ const validateOperatorRule = (
|
|
|
840
841
|
// Format as YYYY-MM-DD
|
|
841
842
|
const date = new Date(value);
|
|
842
843
|
return `${date.getUTCFullYear()}-${String(
|
|
843
|
-
date.getUTCMonth() + 1
|
|
844
|
+
date.getUTCMonth() + 1,
|
|
844
845
|
).padStart(2, "0")}-${String(date.getUTCDate()).padStart(2, "0")}`;
|
|
845
846
|
}
|
|
846
847
|
// Return UTC midnight timestamp for comparison
|
|
@@ -1013,7 +1014,7 @@ const validateOperatorRule = (
|
|
|
1013
1014
|
description: "",
|
|
1014
1015
|
message,
|
|
1015
1016
|
},
|
|
1016
|
-
field
|
|
1017
|
+
field,
|
|
1017
1018
|
);
|
|
1018
1019
|
}
|
|
1019
1020
|
};
|
|
@@ -1023,7 +1024,7 @@ const generateErrorMessage = (
|
|
|
1023
1024
|
fieldLabel,
|
|
1024
1025
|
additionalValues = {},
|
|
1025
1026
|
error_messages,
|
|
1026
|
-
custom_message
|
|
1027
|
+
custom_message,
|
|
1027
1028
|
) => {
|
|
1028
1029
|
let message = custom_message ?? error_messages[ruleKey];
|
|
1029
1030
|
message = message?.replace(`{field}`, fieldLabel);
|
|
@@ -1041,7 +1042,7 @@ const handleRule = (
|
|
|
1041
1042
|
currentPath,
|
|
1042
1043
|
formData,
|
|
1043
1044
|
error_messages,
|
|
1044
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
1045
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1045
1046
|
) => {
|
|
1046
1047
|
const ruleValue = rule?.value;
|
|
1047
1048
|
let messageValue = Array.isArray(ruleValue)
|
|
@@ -1059,7 +1060,7 @@ const handleRule = (
|
|
|
1059
1060
|
|
|
1060
1061
|
const labelValuePairs = ruleValues.map((val) => {
|
|
1061
1062
|
const matched = fieldChoices.find(
|
|
1062
|
-
(item) => String(item.value) === String(val)
|
|
1063
|
+
(item) => String(item.value) === String(val),
|
|
1063
1064
|
);
|
|
1064
1065
|
return matched ? `${matched.label} (${matched.value})` : val;
|
|
1065
1066
|
});
|
|
@@ -1079,10 +1080,10 @@ const handleRule = (
|
|
|
1079
1080
|
fieldLabel,
|
|
1080
1081
|
extraValues,
|
|
1081
1082
|
error_messages,
|
|
1082
|
-
custom_message
|
|
1083
|
+
custom_message,
|
|
1083
1084
|
),
|
|
1084
1085
|
},
|
|
1085
|
-
field
|
|
1086
|
+
field,
|
|
1086
1087
|
);
|
|
1087
1088
|
|
|
1088
1089
|
switch (rule.case) {
|
|
@@ -1102,7 +1103,7 @@ const handleRule = (
|
|
|
1102
1103
|
addValidationError(
|
|
1103
1104
|
"NOT_ONE_OF",
|
|
1104
1105
|
{ value: messageValue },
|
|
1105
|
-
custom_message
|
|
1106
|
+
custom_message,
|
|
1106
1107
|
);
|
|
1107
1108
|
break;
|
|
1108
1109
|
case constants.rulesTypes.NOT_ALLOWED:
|
|
@@ -1119,7 +1120,7 @@ const handleRule = (
|
|
|
1119
1120
|
addError,
|
|
1120
1121
|
currentPath,
|
|
1121
1122
|
error_messages,
|
|
1122
|
-
custom_message
|
|
1123
|
+
custom_message,
|
|
1123
1124
|
);
|
|
1124
1125
|
break;
|
|
1125
1126
|
case constants.rulesTypes.REGEX:
|
|
@@ -1130,7 +1131,7 @@ const handleRule = (
|
|
|
1130
1131
|
addError,
|
|
1131
1132
|
currentPath,
|
|
1132
1133
|
error_messages,
|
|
1133
|
-
custom_message
|
|
1134
|
+
custom_message,
|
|
1134
1135
|
);
|
|
1135
1136
|
break;
|
|
1136
1137
|
case constants.rulesTypes.OPERATOR:
|
|
@@ -1143,7 +1144,7 @@ const handleRule = (
|
|
|
1143
1144
|
formData,
|
|
1144
1145
|
error_messages,
|
|
1145
1146
|
custom_message,
|
|
1146
|
-
timeZone
|
|
1147
|
+
timeZone,
|
|
1147
1148
|
);
|
|
1148
1149
|
break;
|
|
1149
1150
|
default:
|
|
@@ -1166,7 +1167,7 @@ const validateField = (
|
|
|
1166
1167
|
existingForm,
|
|
1167
1168
|
getNodes = true,
|
|
1168
1169
|
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1169
|
-
translatedPath = null
|
|
1170
|
+
translatedPath = null,
|
|
1170
1171
|
) => {
|
|
1171
1172
|
const { is_m2a_item, staticType = null, parentInterface } = field?.meta;
|
|
1172
1173
|
const currentPath = fieldPath
|
|
@@ -1183,7 +1184,7 @@ const validateField = (
|
|
|
1183
1184
|
onlyFormFields == true &&
|
|
1184
1185
|
value === undefined &&
|
|
1185
1186
|
![constants.interfaces.TRANSLATIONS, constants.interfaces.SEO].includes(
|
|
1186
|
-
field?.meta?.interface
|
|
1187
|
+
field?.meta?.interface,
|
|
1187
1188
|
)
|
|
1188
1189
|
) {
|
|
1189
1190
|
if (
|
|
@@ -1197,7 +1198,7 @@ const validateField = (
|
|
|
1197
1198
|
const translationFieldPath = trimBasicPath(currentPath, staticType);
|
|
1198
1199
|
const existingItemValue = getValue(
|
|
1199
1200
|
existingForm,
|
|
1200
|
-
translationFieldPath
|
|
1201
|
+
translationFieldPath,
|
|
1201
1202
|
)?.find((item) => item.languages_code === langCode)?.[
|
|
1202
1203
|
`${field.key.split(".").pop()}`
|
|
1203
1204
|
];
|
|
@@ -1205,7 +1206,7 @@ const validateField = (
|
|
|
1205
1206
|
if (isEmpty(existingItemValue)) {
|
|
1206
1207
|
const message = error_messages.REQUIRED.replace(
|
|
1207
1208
|
`{field}`,
|
|
1208
|
-
formatLabel(`${field.key.split(".").pop()}`)
|
|
1209
|
+
formatLabel(`${field.key.split(".").pop()}`),
|
|
1209
1210
|
);
|
|
1210
1211
|
addError(
|
|
1211
1212
|
currentPath,
|
|
@@ -1216,10 +1217,10 @@ const validateField = (
|
|
|
1216
1217
|
description: "",
|
|
1217
1218
|
message,
|
|
1218
1219
|
},
|
|
1219
|
-
field
|
|
1220
|
+
field,
|
|
1220
1221
|
);
|
|
1221
1222
|
}
|
|
1222
|
-
} else return;
|
|
1223
|
+
} else if (field?.meta?.interface !== constants.interfaces.OBJECT) return;
|
|
1223
1224
|
}
|
|
1224
1225
|
|
|
1225
1226
|
const fieldLabel = formatLabel(field.display_label);
|
|
@@ -1238,14 +1239,15 @@ const validateField = (
|
|
|
1238
1239
|
language_codes,
|
|
1239
1240
|
existingForm,
|
|
1240
1241
|
getNodes,
|
|
1241
|
-
translatedPath
|
|
1242
|
+
translatedPath,
|
|
1242
1243
|
);
|
|
1243
1244
|
|
|
1244
1245
|
if (
|
|
1245
1246
|
field.type === constants.types.OBJECT &&
|
|
1246
|
-
field.children
|
|
1247
|
-
|
|
1248
|
-
|
|
1247
|
+
field.children
|
|
1248
|
+
// &&
|
|
1249
|
+
// !isEmpty(value) &&
|
|
1250
|
+
// typeChecks[constants.types.OBJECT](value)
|
|
1249
1251
|
) {
|
|
1250
1252
|
let itemSchemaId = null;
|
|
1251
1253
|
let childrenToValidate = field.children;
|
|
@@ -1257,7 +1259,7 @@ const validateField = (
|
|
|
1257
1259
|
childrenToValidate = [];
|
|
1258
1260
|
} else {
|
|
1259
1261
|
childrenToValidate = field.children.filter(
|
|
1260
|
-
(child) => child.schema_id === itemSchemaId
|
|
1262
|
+
(child) => child.schema_id === itemSchemaId,
|
|
1261
1263
|
);
|
|
1262
1264
|
}
|
|
1263
1265
|
}
|
|
@@ -1265,7 +1267,7 @@ const validateField = (
|
|
|
1265
1267
|
childrenToValidate.forEach((child) =>
|
|
1266
1268
|
validateField(
|
|
1267
1269
|
child,
|
|
1268
|
-
value[child.key.split(".").pop()],
|
|
1270
|
+
!isEmpty(value) ? value[child.key.split(".").pop()] : null,
|
|
1269
1271
|
currentPath,
|
|
1270
1272
|
addError,
|
|
1271
1273
|
formData,
|
|
@@ -1278,8 +1280,8 @@ const validateField = (
|
|
|
1278
1280
|
existingForm,
|
|
1279
1281
|
false,
|
|
1280
1282
|
timeZone,
|
|
1281
|
-
null
|
|
1282
|
-
)
|
|
1283
|
+
null,
|
|
1284
|
+
),
|
|
1283
1285
|
);
|
|
1284
1286
|
} else if (field.type === constants.types.ARRAY && Array.isArray(value)) {
|
|
1285
1287
|
const itemType = field?.array_type || field?.schema_definition?.type;
|
|
@@ -1301,7 +1303,7 @@ const validateField = (
|
|
|
1301
1303
|
itemPath,
|
|
1302
1304
|
formData,
|
|
1303
1305
|
error_messages,
|
|
1304
|
-
timeZone
|
|
1306
|
+
timeZone,
|
|
1305
1307
|
);
|
|
1306
1308
|
}
|
|
1307
1309
|
|
|
@@ -1316,7 +1318,7 @@ const validateField = (
|
|
|
1316
1318
|
{
|
|
1317
1319
|
type: itemType,
|
|
1318
1320
|
},
|
|
1319
|
-
error_messages
|
|
1321
|
+
error_messages,
|
|
1320
1322
|
),
|
|
1321
1323
|
});
|
|
1322
1324
|
}
|
|
@@ -1360,7 +1362,7 @@ const validateField = (
|
|
|
1360
1362
|
existingForm,
|
|
1361
1363
|
false,
|
|
1362
1364
|
timeZone,
|
|
1363
|
-
trPath
|
|
1365
|
+
trPath,
|
|
1364
1366
|
);
|
|
1365
1367
|
});
|
|
1366
1368
|
});
|
|
@@ -1374,7 +1376,7 @@ const validateField = (
|
|
|
1374
1376
|
currentPath,
|
|
1375
1377
|
formData,
|
|
1376
1378
|
error_messages,
|
|
1377
|
-
timeZone
|
|
1379
|
+
timeZone,
|
|
1378
1380
|
)
|
|
1379
1381
|
) {
|
|
1380
1382
|
addError(
|
|
@@ -1385,7 +1387,7 @@ const validateField = (
|
|
|
1385
1387
|
description: "",
|
|
1386
1388
|
message: error_messages.INVALID_VALUE?.replace(`{field}`, fieldLabel),
|
|
1387
1389
|
},
|
|
1388
|
-
field
|
|
1390
|
+
field,
|
|
1389
1391
|
);
|
|
1390
1392
|
}
|
|
1391
1393
|
}
|
|
@@ -1398,7 +1400,7 @@ const applyValidations = (
|
|
|
1398
1400
|
currentPath,
|
|
1399
1401
|
formData,
|
|
1400
1402
|
error_messages,
|
|
1401
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
1403
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1402
1404
|
) => {
|
|
1403
1405
|
if (
|
|
1404
1406
|
!field.validations ||
|
|
@@ -1418,8 +1420,8 @@ const applyValidations = (
|
|
|
1418
1420
|
currentPath,
|
|
1419
1421
|
formData,
|
|
1420
1422
|
error_messages,
|
|
1421
|
-
timeZone
|
|
1422
|
-
) === false
|
|
1423
|
+
timeZone,
|
|
1424
|
+
) === false,
|
|
1423
1425
|
);
|
|
1424
1426
|
};
|
|
1425
1427
|
|
|
@@ -1526,13 +1528,13 @@ const validate = (data) => {
|
|
|
1526
1528
|
typeChecks[constants.types.OBJECT](firstParentValue)
|
|
1527
1529
|
) {
|
|
1528
1530
|
const codeKey = Object.keys(firstParentValue).find((key) =>
|
|
1529
|
-
key.includes(languageKey)
|
|
1531
|
+
key.includes(languageKey),
|
|
1530
1532
|
);
|
|
1531
1533
|
const codeValue = codeKey ? firstParentValue[codeKey] : null;
|
|
1532
1534
|
if (codeValue) {
|
|
1533
1535
|
const translation_key = fieldPath.replace(
|
|
1534
1536
|
firstParent,
|
|
1535
|
-
`${secondParent}.${codeValue}
|
|
1537
|
+
`${secondParent}.${codeValue}`,
|
|
1536
1538
|
);
|
|
1537
1539
|
if (translation_key) {
|
|
1538
1540
|
obj.translation_path = translation_key;
|
|
@@ -1555,7 +1557,7 @@ const validate = (data) => {
|
|
|
1555
1557
|
if (!data) {
|
|
1556
1558
|
const message = error_messages.REQUIRED.replace(
|
|
1557
1559
|
`{field}`,
|
|
1558
|
-
formatLabel("data")
|
|
1560
|
+
formatLabel("data"),
|
|
1559
1561
|
);
|
|
1560
1562
|
addError(
|
|
1561
1563
|
"data",
|
|
@@ -1565,7 +1567,7 @@ const validate = (data) => {
|
|
|
1565
1567
|
description: "",
|
|
1566
1568
|
message,
|
|
1567
1569
|
},
|
|
1568
|
-
defaultField
|
|
1570
|
+
defaultField,
|
|
1569
1571
|
);
|
|
1570
1572
|
return result;
|
|
1571
1573
|
}
|
|
@@ -1574,7 +1576,7 @@ const validate = (data) => {
|
|
|
1574
1576
|
if (!typeChecks[constants.types.OBJECT](data)) {
|
|
1575
1577
|
const message = error_messages.INVALID_TYPE.replace(
|
|
1576
1578
|
`{field}`,
|
|
1577
|
-
formatLabel("data")
|
|
1579
|
+
formatLabel("data"),
|
|
1578
1580
|
).replace(`{type}`, constants.types.OBJECT);
|
|
1579
1581
|
addError(
|
|
1580
1582
|
"data",
|
|
@@ -1584,7 +1586,7 @@ const validate = (data) => {
|
|
|
1584
1586
|
description: "",
|
|
1585
1587
|
message,
|
|
1586
1588
|
},
|
|
1587
|
-
defaultField
|
|
1589
|
+
defaultField,
|
|
1588
1590
|
);
|
|
1589
1591
|
return result;
|
|
1590
1592
|
}
|
|
@@ -1597,7 +1599,7 @@ const validate = (data) => {
|
|
|
1597
1599
|
if (fieldValue == null || fieldValue == undefined) {
|
|
1598
1600
|
const message = error_messages.REQUIRED.replace(
|
|
1599
1601
|
`{field}`,
|
|
1600
|
-
formatLabel(key)
|
|
1602
|
+
formatLabel(key),
|
|
1601
1603
|
);
|
|
1602
1604
|
addError(
|
|
1603
1605
|
key,
|
|
@@ -1607,7 +1609,7 @@ const validate = (data) => {
|
|
|
1607
1609
|
description: "",
|
|
1608
1610
|
message,
|
|
1609
1611
|
},
|
|
1610
|
-
defaultField
|
|
1612
|
+
defaultField,
|
|
1611
1613
|
);
|
|
1612
1614
|
return;
|
|
1613
1615
|
}
|
|
@@ -1616,7 +1618,7 @@ const validate = (data) => {
|
|
|
1616
1618
|
if (!typeChecks[expectedType] || !typeChecks[expectedType](fieldValue)) {
|
|
1617
1619
|
const message = error_messages.INVALID_TYPE.replace(
|
|
1618
1620
|
`{field}`,
|
|
1619
|
-
key
|
|
1621
|
+
key,
|
|
1620
1622
|
).replace(`{type}`, expectedType);
|
|
1621
1623
|
addError(
|
|
1622
1624
|
key,
|
|
@@ -1626,7 +1628,7 @@ const validate = (data) => {
|
|
|
1626
1628
|
description: "",
|
|
1627
1629
|
message,
|
|
1628
1630
|
},
|
|
1629
|
-
defaultField
|
|
1631
|
+
defaultField,
|
|
1630
1632
|
);
|
|
1631
1633
|
return;
|
|
1632
1634
|
}
|
|
@@ -1644,7 +1646,7 @@ const validate = (data) => {
|
|
|
1644
1646
|
) {
|
|
1645
1647
|
const message = error_messages.INVALID_TYPE.replace(
|
|
1646
1648
|
`{field}`,
|
|
1647
|
-
`${key}[${index}]
|
|
1649
|
+
`${key}[${index}]`,
|
|
1648
1650
|
).replace(`{type}`, arrayItemType);
|
|
1649
1651
|
addError(
|
|
1650
1652
|
`${key}[${index}]`,
|
|
@@ -1654,7 +1656,7 @@ const validate = (data) => {
|
|
|
1654
1656
|
description: "",
|
|
1655
1657
|
message,
|
|
1656
1658
|
},
|
|
1657
|
-
defaultField
|
|
1659
|
+
defaultField,
|
|
1658
1660
|
);
|
|
1659
1661
|
}
|
|
1660
1662
|
});
|
|
@@ -1665,7 +1667,7 @@ const validate = (data) => {
|
|
|
1665
1667
|
if (!constants.API_VERSIONS.includes(apiVersion)) {
|
|
1666
1668
|
const message = error_messages.IN.replace(
|
|
1667
1669
|
`{field}`,
|
|
1668
|
-
formatLabel("apiVersion")
|
|
1670
|
+
formatLabel("apiVersion"),
|
|
1669
1671
|
).replace(`{value}`, constants.API_VERSIONS.join(", "));
|
|
1670
1672
|
addError(
|
|
1671
1673
|
"apiVersion",
|
|
@@ -1675,7 +1677,7 @@ const validate = (data) => {
|
|
|
1675
1677
|
description: "",
|
|
1676
1678
|
message,
|
|
1677
1679
|
},
|
|
1678
|
-
defaultField
|
|
1680
|
+
defaultField,
|
|
1679
1681
|
);
|
|
1680
1682
|
}
|
|
1681
1683
|
|
|
@@ -1693,7 +1695,7 @@ const validate = (data) => {
|
|
|
1693
1695
|
|
|
1694
1696
|
if (!isSeparatedFields) {
|
|
1695
1697
|
schemaFields = fields.filter(
|
|
1696
|
-
(field) => field?.schema_id?.toString() === formId?.toString()
|
|
1698
|
+
(field) => field?.schema_id?.toString() === formId?.toString(),
|
|
1697
1699
|
);
|
|
1698
1700
|
}
|
|
1699
1701
|
|
|
@@ -1728,7 +1730,7 @@ const validate = (data) => {
|
|
|
1728
1730
|
{
|
|
1729
1731
|
field: formatLabel(fieldKey),
|
|
1730
1732
|
},
|
|
1731
|
-
error_messages
|
|
1733
|
+
error_messages,
|
|
1732
1734
|
),
|
|
1733
1735
|
});
|
|
1734
1736
|
}
|
|
@@ -1751,7 +1753,7 @@ const validate = (data) => {
|
|
|
1751
1753
|
existingForm,
|
|
1752
1754
|
true,
|
|
1753
1755
|
timeZone,
|
|
1754
|
-
null
|
|
1756
|
+
null,
|
|
1755
1757
|
);
|
|
1756
1758
|
});
|
|
1757
1759
|
return result;
|