nox-validation 1.1.2 → 1.1.3
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 +41 -6
- package/lib/validate.js +34 -5
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -355,7 +355,7 @@ const convertTypesV1 = (field) => {
|
|
|
355
355
|
return { type, array_type, find_relations };
|
|
356
356
|
};
|
|
357
357
|
|
|
358
|
-
const generateField = (name, path, schema_definition_type, type, childrenFields = []) => {
|
|
358
|
+
const generateField = (name, path, schema_definition_type, type, childrenFields = [],relationType="none") => {
|
|
359
359
|
childrenFields = childrenFields?.map((child) => {
|
|
360
360
|
return {
|
|
361
361
|
...child,
|
|
@@ -375,6 +375,7 @@ const generateField = (name, path, schema_definition_type, type, childrenFields
|
|
|
375
375
|
required: false,
|
|
376
376
|
nullable: false,
|
|
377
377
|
hidden: false,
|
|
378
|
+
interface:relationType
|
|
378
379
|
},
|
|
379
380
|
validations: [],
|
|
380
381
|
schema_definition: {
|
|
@@ -426,9 +427,24 @@ const generateRelationalField = (key = "", collectionFields = [], relationType)
|
|
|
426
427
|
const deleteField = generateField(
|
|
427
428
|
"delete",
|
|
428
429
|
`${key}.delete`,
|
|
429
|
-
constants.types.
|
|
430
|
+
constants.types.OBJECT,
|
|
430
431
|
constants.types.ARRAY
|
|
431
432
|
);
|
|
433
|
+
deleteField.children = [
|
|
434
|
+
generateField(
|
|
435
|
+
"collection",
|
|
436
|
+
`${key}.delete.collection`,
|
|
437
|
+
constants.types.STRING,
|
|
438
|
+
constants.types.STRING
|
|
439
|
+
),
|
|
440
|
+
generateField("sort", `${key}.delete.sort`, constants.types.NUMBER, constants.types.NUMBER),
|
|
441
|
+
generateField(
|
|
442
|
+
"item",
|
|
443
|
+
`${key}.delete.item`,
|
|
444
|
+
constants.types.OBJECT_ID,
|
|
445
|
+
constants.types.OBJECT_ID
|
|
446
|
+
),
|
|
447
|
+
];
|
|
432
448
|
const createField = generateField(
|
|
433
449
|
"create",
|
|
434
450
|
`${key}.create`,
|
|
@@ -449,7 +465,8 @@ const generateRelationalField = (key = "", collectionFields = [], relationType)
|
|
|
449
465
|
`${key}.create.item`,
|
|
450
466
|
constants.types.OBJECT,
|
|
451
467
|
constants.types.OBJECT,
|
|
452
|
-
collectionFields
|
|
468
|
+
collectionFields,
|
|
469
|
+
relationType
|
|
453
470
|
),
|
|
454
471
|
];
|
|
455
472
|
const updateField = generateField(
|
|
@@ -472,7 +489,8 @@ const generateRelationalField = (key = "", collectionFields = [], relationType)
|
|
|
472
489
|
`${key}.update.item`,
|
|
473
490
|
constants.types.OBJECT,
|
|
474
491
|
constants.types.OBJECT,
|
|
475
|
-
collectionFields
|
|
492
|
+
collectionFields,
|
|
493
|
+
relationType
|
|
476
494
|
),
|
|
477
495
|
];
|
|
478
496
|
return [existingField, deleteField, createField, updateField];
|
|
@@ -633,7 +651,23 @@ const getCachedOrFetchFields = (schemaId, allFields, relational_fields) => {
|
|
|
633
651
|
return fields;
|
|
634
652
|
};
|
|
635
653
|
|
|
636
|
-
const getChildFields = (relationDetail, allFields, relational_fields, isTranslation) => {
|
|
654
|
+
const getChildFields = (relationDetail, allFields, relational_fields, isTranslation,name) => {
|
|
655
|
+
if(name === "my_m2a"){
|
|
656
|
+
// this_collection: '67b41ff9d6461cfeabfc1216',
|
|
657
|
+
// this_field: '_id',
|
|
658
|
+
// foreign_collection: [
|
|
659
|
+
// '6799ea49736e3f1cdbaa5f67',
|
|
660
|
+
// '6799ea54736e3f1cdbaa5f82',
|
|
661
|
+
// '6799ea9a736e3f1cdbaa5fbc'
|
|
662
|
+
// ],
|
|
663
|
+
// foreign_field: 'Primary Key',
|
|
664
|
+
// junction_collection: '67f35f70ff1653a843cca6b7',
|
|
665
|
+
// junction_field_this: 'time_test_id',
|
|
666
|
+
// junction_field_foreign: 'item',
|
|
667
|
+
// junction_field_ref: 'collection',
|
|
668
|
+
// foreign_collection_ref: 'products, comments, categories'
|
|
669
|
+
console.log(relationDetail.foreign_collection, 'test',name,relationDetail);
|
|
670
|
+
}
|
|
637
671
|
let key = isTranslation
|
|
638
672
|
? [
|
|
639
673
|
...(Array.isArray(relationDetail.junction_collection)
|
|
@@ -714,7 +748,7 @@ const buildNestedStructure = ({
|
|
|
714
748
|
relationDetail,
|
|
715
749
|
allFields,
|
|
716
750
|
relational_fields,
|
|
717
|
-
item?.meta?.interface === constants.interfaces.TRANSLATIONS
|
|
751
|
+
item?.meta?.interface === constants.interfaces.TRANSLATIONS,key
|
|
718
752
|
);
|
|
719
753
|
} else {
|
|
720
754
|
childFields = getCachedFields(relationDetail, relational_fields);
|
|
@@ -740,6 +774,7 @@ const buildNestedStructure = ({
|
|
|
740
774
|
|
|
741
775
|
const node = {
|
|
742
776
|
field_id: item?._id,
|
|
777
|
+
schema_id: item?.schema_id,
|
|
743
778
|
display_label: pathParts[pathParts.length - 1],
|
|
744
779
|
key,
|
|
745
780
|
value: key,
|
package/lib/validate.js
CHANGED
|
@@ -576,7 +576,37 @@ const validateField = (
|
|
|
576
576
|
value &&
|
|
577
577
|
typeChecks[constants.types.OBJECT](value)
|
|
578
578
|
) {
|
|
579
|
-
|
|
579
|
+
const isManyToAnyItem =
|
|
580
|
+
field.display_label === "item" && field?.meta?.interface === constants.interfaces.MANY_TO_ANY;
|
|
581
|
+
|
|
582
|
+
const defaultKeys = new Set([
|
|
583
|
+
"_id",
|
|
584
|
+
"created_at",
|
|
585
|
+
"updated_at",
|
|
586
|
+
"__v",
|
|
587
|
+
"created_by",
|
|
588
|
+
"updated_by",
|
|
589
|
+
"nox_created_by",
|
|
590
|
+
"nox_updated_by",
|
|
591
|
+
"nox_created_at",
|
|
592
|
+
"nox_updated_at",
|
|
593
|
+
]);
|
|
594
|
+
|
|
595
|
+
let itemSchemaId = null;
|
|
596
|
+
|
|
597
|
+
if (isManyToAnyItem) {
|
|
598
|
+
const itemKey = Object.keys(value).find((key) => !defaultKeys.has(key));
|
|
599
|
+
if (itemKey) {
|
|
600
|
+
const childField = field.children.find((child) => child.display_label === itemKey);
|
|
601
|
+
itemSchemaId = childField?.schema_id ?? null;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const childrenToValidate = itemSchemaId
|
|
606
|
+
? field.children.filter((child) => child.schema_id === itemSchemaId)
|
|
607
|
+
: field.children;
|
|
608
|
+
|
|
609
|
+
childrenToValidate.forEach((child) =>
|
|
580
610
|
validateField(
|
|
581
611
|
child,
|
|
582
612
|
value[child.key.split(".").pop()],
|
|
@@ -668,6 +698,9 @@ const schema = {
|
|
|
668
698
|
};
|
|
669
699
|
|
|
670
700
|
const validate = (data) => {
|
|
701
|
+
if (!data?.language) {
|
|
702
|
+
data.language = constants.LANGUAGES.en;
|
|
703
|
+
}
|
|
671
704
|
const {
|
|
672
705
|
formData,
|
|
673
706
|
isSeparatedFields,
|
|
@@ -681,10 +714,6 @@ const validate = (data) => {
|
|
|
681
714
|
language,
|
|
682
715
|
maxLevel,
|
|
683
716
|
} = data;
|
|
684
|
-
|
|
685
|
-
if (!data?.language) {
|
|
686
|
-
data.language = constants.LANGUAGES.en;
|
|
687
|
-
}
|
|
688
717
|
|
|
689
718
|
const error_messages = constants.LOCALE_MESSAGES[language];
|
|
690
719
|
|