nox-validation 1.6.9 → 1.7.1

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/validate.js +38 -11
  2. package/package.json +1 -1
package/lib/validate.js CHANGED
@@ -447,7 +447,9 @@ const validateMetaRules = (
447
447
  // Translations interface needs to be handled
448
448
  (field?.meta?.interface === constants.interfaces.TRANSLATIONS &&
449
449
  language_codes?.length &&
450
- !onlyFormFields) ||
450
+ (onlyFormFields
451
+ ? isEmpty(getValue(existingForm, currentPath))
452
+ : true)) ||
451
453
  // OBJECT or ITEMS interfaces
452
454
  ((field?.meta?.interface === constants.interfaces.OBJECT ||
453
455
  field?.meta?.interface === constants.interfaces.ITEMS) &&
@@ -546,7 +548,9 @@ const validateMetaRules = (
546
548
  node.value,
547
549
  node.key,
548
550
  (path) => {
549
- const newPath = path.replace(/\[0\]\./, `.${lang}.`);
551
+ const newPath = path
552
+ .replace(/\[0\]\./, `.${lang}.`)
553
+ ?.replace("create", "");
550
554
  return newPath;
551
555
  }
552
556
  );
@@ -556,7 +560,7 @@ const validateMetaRules = (
556
560
  });
557
561
 
558
562
  transformedPath = rebuildFullPath(node.value, node.key, (path) =>
559
- path.replace(/\[0\]\./, `.${lang}.`)
563
+ path.replace(/\[0\]\./, `.${lang}.`)?.replace("create", "")
560
564
  );
561
565
  }
562
566
 
@@ -1119,7 +1123,9 @@ const validateField = (
1119
1123
  if (
1120
1124
  onlyFormFields == true &&
1121
1125
  value === undefined &&
1122
- field?.meta?.interface !== constants.interfaces.SEO
1126
+ ![constants.interfaces.TRANSLATIONS, constants.interfaces.SEO].includes(
1127
+ field?.meta?.interface
1128
+ )
1123
1129
  )
1124
1130
  return;
1125
1131
 
@@ -1233,7 +1239,20 @@ const validateField = (
1233
1239
  }
1234
1240
  if (field.children?.length > 0) {
1235
1241
  value.forEach((item, index) => {
1236
- field.children.forEach((child) =>
1242
+ field.children.forEach((child) => {
1243
+ let trPath =
1244
+ field?.meta?.parentInterface ===
1245
+ constants.interfaces.TRANSLATIONS && item["languages_code"]
1246
+ ? `${currentPath}.${item["languages_code"]}`
1247
+ : null;
1248
+
1249
+ if (
1250
+ trPath &&
1251
+ field.meta?.staticType === "update" &&
1252
+ trPath.includes(".update.")
1253
+ )
1254
+ trPath = trPath.replace(".update.", ".");
1255
+
1237
1256
  validateField(
1238
1257
  child,
1239
1258
  item[child.key.split(".").pop()],
@@ -1249,12 +1268,9 @@ const validateField = (
1249
1268
  existingForm,
1250
1269
  false,
1251
1270
  timeZone,
1252
- field?.meta?.parentInterface ===
1253
- constants.interfaces.TRANSLATIONS && item["languages_code"]
1254
- ? `${currentPath}.${item["languages_code"]}`
1255
- : null
1256
- )
1257
- );
1271
+ trPath
1272
+ );
1273
+ });
1258
1274
  });
1259
1275
  }
1260
1276
  } else {
@@ -1351,6 +1367,14 @@ const validate = (data) => {
1351
1367
  if (data.onlyFormFields === undefined) {
1352
1368
  data.onlyFormFields = false;
1353
1369
  }
1370
+
1371
+ const refFields = [
1372
+ "created_by",
1373
+ "updated_by",
1374
+ "nox_created_by",
1375
+ "nox_updated_by",
1376
+ ];
1377
+
1354
1378
  let {
1355
1379
  formData,
1356
1380
  isSeparatedFields,
@@ -1367,6 +1391,7 @@ const validate = (data) => {
1367
1391
  existingForm = {},
1368
1392
  timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
1369
1393
  } = data;
1394
+ byPassKeys = [...refFields, ...byPassKeys];
1370
1395
 
1371
1396
  const error_messages =
1372
1397
  constants.LOCALE_MESSAGES[language] ??
@@ -1565,6 +1590,8 @@ const validate = (data) => {
1565
1590
 
1566
1591
  // Validate Parameters END
1567
1592
 
1593
+ fields = fields.filter((field) => !refFields.includes(field?.field));
1594
+
1568
1595
  // Get Relational Field
1569
1596
  let schemaFields = fields;
1570
1597
  let allFields = isSeparatedFields ? [] : fields;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-validation",
3
- "version": "1.6.9",
3
+ "version": "1.7.1",
4
4
  "description": "validate dynamic schema",
5
5
  "main": "index.js",
6
6
  "scripts": {