nox-validation 1.1.6 → 1.1.7

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.
Files changed (2) hide show
  1. package/lib/helpers.js +29 -4
  2. package/package.json +1 -1
package/lib/helpers.js CHANGED
@@ -384,6 +384,22 @@ const generateField = (name, path, schema_definition_type, type, childrenFields
384
384
  };
385
385
  };
386
386
 
387
+ const createChildrenFieldsFiles = (key) => {
388
+ const existingField = generateField(
389
+ "existing",
390
+ `${key}.existing`,
391
+ constants.types.OBJECT_ID,
392
+ constants.types.ARRAY
393
+ );
394
+ const deleteField = generateField(
395
+ "delete",
396
+ `${key}.delete`,
397
+ constants.types.OBJECT_ID,
398
+ constants.types.ARRAY
399
+ );
400
+ return [existingField, deleteField];
401
+ }
402
+
387
403
  const generateRelationalFieldV1 = (key = "", collectionFields = [], relationType) => {
388
404
  if (relationType === constants.interfaces.MANY_TO_ANY) {
389
405
  return [
@@ -707,6 +723,11 @@ const buildNestedStructure = ({
707
723
  schemaFields.forEach((item) => {
708
724
  const pathParts = item.path.split(".");
709
725
  const key = pathParts.join(".");
726
+ const isV2File = apiVersion === constants.API_VERSION.V2 && [
727
+ constants.interfaces.FILES,
728
+ constants.interfaces.FILE,
729
+ constants.interfaces.FILE_IMAGE,
730
+ ].includes(item?.meta?.interface);
710
731
 
711
732
  const currentDepth = currentDepthMap.get(isRoot ? item.path : rootPath) || 0;
712
733
 
@@ -714,9 +735,7 @@ const buildNestedStructure = ({
714
735
 
715
736
  let childFields;
716
737
 
717
- const definedType = generateType(item, apiVersion);
718
- // apiVersion === constants.API_VERSION.V1 ? convertTypesV1(item) : convertTypes(item);
719
- // const isUserKey = default_fields.some((field) => item?.path?.includes(field));
738
+ let definedType = generateType(item, apiVersion);
720
739
 
721
740
  if (definedType.find_relations && currentDepth <= maxLevel) {
722
741
  const relationDetail = getForeignCollectionDetails({
@@ -757,6 +776,12 @@ const buildNestedStructure = ({
757
776
  }
758
777
  }
759
778
 
779
+ if(isV2File){
780
+ definedType.array_type = constants.types.OBJECT;
781
+ definedType.type = constants.types.OBJECT;
782
+ childFields = createChildrenFieldsFiles(key);
783
+ }
784
+
760
785
  const node = {
761
786
  field_id: item?._id,
762
787
  schema_id: item?.schema_id,
@@ -776,7 +801,7 @@ const buildNestedStructure = ({
776
801
  custom_error_message: item?.meta?.validations?.validation_msg,
777
802
  children:
778
803
  childFields?.length > 0
779
- ? apiVersion === constants.API_VERSION.V1 &&
804
+ ? isV2File ? childFields:apiVersion === constants.API_VERSION.V1 &&
780
805
  item.meta?.interface !== constants.interfaces.TRANSLATIONS
781
806
  ? generateRelationalFieldV1(key, childFields, item.meta?.interface)
782
807
  : generateRelationalField(key, childFields, item.meta?.interface)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-validation",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "validate dynamic schema",
5
5
  "main": "index.js",
6
6
  "scripts": {