@optimiser/common 1.0.289 → 1.0.291

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/dist/lib/utility.js +138 -53
  2. package/package.json +1 -1
@@ -4422,11 +4422,11 @@ function IsAnotherObjectField(pageData, fieldName) {
4422
4422
  */
4423
4423
  function ValidateUserInput(options) {
4424
4424
  return __awaiter(this, void 0, void 0, function () {
4425
- var inputFields, pageData, documentID, db, action, objectSchema, objectName, pageFields, schemaFields, inputField, msg, _loop_18, _i, inputField_1, name_1, state_1, _loop_19, isValid, _a, pageFields_1, pageField, state_2, err_3;
4425
+ var inputFields, pageData, documentID, db, action, objectSchema, objectName, pageFields, schemaFields, inputField, msg, _loop_18, _i, inputField_1, name_1, state_1, _loop_19, isValid, validateResp, _a, pageFields_1, pageField, state_2, countryData, err_3;
4426
4426
  return __generator(this, function (_b) {
4427
4427
  switch (_b.label) {
4428
4428
  case 0:
4429
- _b.trys.push([0, 5, , 6]);
4429
+ _b.trys.push([0, 7, , 8]);
4430
4430
  inputFields = options.userInput;
4431
4431
  pageData = options.pageData;
4432
4432
  documentID = options.objectID;
@@ -4458,9 +4458,9 @@ function ValidateUserInput(options) {
4458
4458
  }
4459
4459
  }
4460
4460
  _loop_19 = function (pageField) {
4461
- var fieldName, fieldData, field, searchQuery, result, _a, filter, searchObj, result, searchObj, totalRecord, _b, schemaData, result, searchObj, result, schemaData, result, searchObj, totalRecord, regexpression, phone;
4462
- return __generator(this, function (_c) {
4463
- switch (_c.label) {
4461
+ var fieldName, fieldData, field, searchQuery, result, _a, filter, searchObj, result, searchObj, totalRecord, _b, schemaData, result, searchObj, result, schemaData, result, searchObj, totalRecord, regexpression, phone, files, _i, fieldData_1, obj, searchObj, totalRecord, searchObj, result, _c, fieldData_2, obj;
4462
+ return __generator(this, function (_d) {
4463
+ switch (_d.label) {
4464
4464
  case 0:
4465
4465
  if (msg != "") {
4466
4466
  return [2 /*return*/, "break"];
@@ -4468,7 +4468,7 @@ function ValidateUserInput(options) {
4468
4468
  fieldName = pageField.Name;
4469
4469
  fieldData = inputFields[fieldName];
4470
4470
  field = schemaFields.find(function (x) { return x.Name == fieldName; });
4471
- if (!field) return [3 /*break*/, 38];
4471
+ if (!field) return [3 /*break*/, 52];
4472
4472
  if (fieldData && IsStringValue(fieldData) && field.UIDataType != 'dropdown') {
4473
4473
  fieldData = fieldData.trim();
4474
4474
  if (["text", "email", "phone"].includes(field.UIDataType)) {
@@ -4490,15 +4490,15 @@ function ValidateUserInput(options) {
4490
4490
  }
4491
4491
  return [4 /*yield*/, db.collection(objectSchema.Name).findOne(searchQuery)];
4492
4492
  case 1:
4493
- result = _c.sent();
4493
+ result = _d.sent();
4494
4494
  if (result != null) {
4495
4495
  msg = 'Email already exists for ' + field.DisplayName + '!';
4496
4496
  return [2 /*return*/, "break"];
4497
4497
  }
4498
- _c.label = 2;
4498
+ _d.label = 2;
4499
4499
  case 2:
4500
- if (!inputField.includes(fieldName)) return [3 /*break*/, 37];
4501
- if (!(fieldData || fieldData === 0 || fieldData === false)) return [3 /*break*/, 37];
4500
+ if (!inputField.includes(fieldName)) return [3 /*break*/, 51];
4501
+ if (!(fieldData || fieldData === 0 || fieldData === false)) return [3 /*break*/, 51];
4502
4502
  _a = field.UIDataType;
4503
4503
  switch (_a) {
4504
4504
  case 'int': return [3 /*break*/, 3];
@@ -4514,11 +4514,14 @@ function ValidateUserInput(options) {
4514
4514
  case 'multiselect': return [3 /*break*/, 24];
4515
4515
  case 'url': return [3 /*break*/, 34];
4516
4516
  case 'phone': return [3 /*break*/, 35];
4517
- case 'textarea': return [3 /*break*/, 36];
4518
- case 'text': return [3 /*break*/, 36];
4519
- case 'texteditor': return [3 /*break*/, 36];
4517
+ case "image": return [3 /*break*/, 36];
4518
+ case 'file': return [3 /*break*/, 36];
4519
+ case 'textarea': return [3 /*break*/, 45];
4520
+ case 'text': return [3 /*break*/, 45];
4521
+ case 'texteditor': return [3 /*break*/, 45];
4522
+ case 'collection': return [3 /*break*/, 46];
4520
4523
  }
4521
- return [3 /*break*/, 37];
4524
+ return [3 /*break*/, 51];
4522
4525
  case 3:
4523
4526
  {
4524
4527
  if (IsStringValue(fieldData)) {
@@ -4537,14 +4540,14 @@ function ValidateUserInput(options) {
4537
4540
  msg = field.DisplayName + ' value must be smaller then or equal to ' + field.MaxValue;
4538
4541
  }
4539
4542
  }
4540
- return [3 /*break*/, 37];
4543
+ return [3 /*break*/, 51];
4541
4544
  case 4:
4542
4545
  {
4543
4546
  if ((fieldData instanceof Date && !isNaN(inputFields[fieldName])) == false) {
4544
4547
  msg = 'Invalid date for ' + field.DisplayName + '!';
4545
4548
  }
4546
4549
  }
4547
- return [3 /*break*/, 37];
4550
+ return [3 /*break*/, 51];
4548
4551
  case 5:
4549
4552
  {
4550
4553
  isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(fieldData);
@@ -4552,7 +4555,7 @@ function ValidateUserInput(options) {
4552
4555
  msg = 'Invalid time for ' + field.DisplayName + '!';
4553
4556
  }
4554
4557
  }
4555
- return [3 /*break*/, 37];
4558
+ return [3 /*break*/, 51];
4556
4559
  case 6:
4557
4560
  {
4558
4561
  filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
@@ -4560,14 +4563,14 @@ function ValidateUserInput(options) {
4560
4563
  msg = 'Invalid email for ' + field.DisplayName + '!';
4561
4564
  }
4562
4565
  }
4563
- return [3 /*break*/, 37];
4566
+ return [3 /*break*/, 51];
4564
4567
  case 7:
4565
4568
  {
4566
4569
  if (fieldData !== true && fieldData !== false) {
4567
4570
  msg = 'Invalid user input for ' + field.DisplayName + '!';
4568
4571
  }
4569
4572
  }
4570
- return [3 /*break*/, 37];
4573
+ return [3 /*break*/, 51];
4571
4574
  case 8:
4572
4575
  searchObj = { _id: fieldData };
4573
4576
  if (action == 'add') {
@@ -4576,11 +4579,11 @@ function ValidateUserInput(options) {
4576
4579
  ;
4577
4580
  return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
4578
4581
  case 9:
4579
- result = _c.sent();
4582
+ result = _d.sent();
4580
4583
  if (result == null) {
4581
4584
  msg = field.DisplayName + ' does not exist!';
4582
4585
  }
4583
- return [3 /*break*/, 37];
4586
+ return [3 /*break*/, 51];
4584
4587
  case 10:
4585
4588
  if (!Array.isArray(fieldData)) return [3 /*break*/, 16];
4586
4589
  if (!fieldData.length) return [3 /*break*/, 14];
@@ -4591,13 +4594,13 @@ function ValidateUserInput(options) {
4591
4594
  ;
4592
4595
  return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
4593
4596
  case 11:
4594
- totalRecord = _c.sent();
4597
+ totalRecord = _d.sent();
4595
4598
  if (!(objectName == "Activity" && field.Name == 'Attendees')) return [3 /*break*/, 13];
4596
4599
  _b = totalRecord;
4597
4600
  return [4 /*yield*/, db.collection('Contact').find(searchObj).count()];
4598
4601
  case 12:
4599
- totalRecord = _b + _c.sent();
4600
- _c.label = 13;
4602
+ totalRecord = _b + _d.sent();
4603
+ _d.label = 13;
4601
4604
  case 13:
4602
4605
  if (totalRecord !== fieldData.length) {
4603
4606
  msg = field.DisplayName + ' does not exist!';
@@ -4607,25 +4610,25 @@ function ValidateUserInput(options) {
4607
4610
  if (field.IsRequired) {
4608
4611
  msg = field.DisplayName + ' is required!';
4609
4612
  }
4610
- _c.label = 15;
4613
+ _d.label = 15;
4611
4614
  case 15: return [3 /*break*/, 17];
4612
4615
  case 16:
4613
4616
  msg = 'Invalid value for ' + field.DisplayName;
4614
- _c.label = 17;
4615
- case 17: return [3 /*break*/, 37];
4617
+ _d.label = 17;
4618
+ case 17: return [3 /*break*/, 51];
4616
4619
  case 18:
4617
4620
  if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 21];
4618
4621
  if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 20];
4619
4622
  schemaData = null;
4620
4623
  return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
4621
4624
  case 19:
4622
- result = _c.sent();
4625
+ result = _d.sent();
4623
4626
  if (result && result.Data)
4624
4627
  schemaData = result.Data.find(function (x) { return x.Key == fieldData; });
4625
- if (schemaData == null) {
4628
+ if (schemaData == null || (action == 'add' && schemaData.IsActive == false)) {
4626
4629
  msg = field.DisplayName + ' does not exist!';
4627
4630
  }
4628
- _c.label = 20;
4631
+ _d.label = 20;
4629
4632
  case 20: return [3 /*break*/, 23];
4630
4633
  case 21:
4631
4634
  if (!(field.LookupObject !== undefined)) return [3 /*break*/, 23];
@@ -4636,12 +4639,12 @@ function ValidateUserInput(options) {
4636
4639
  ;
4637
4640
  return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
4638
4641
  case 22:
4639
- result = _c.sent();
4642
+ result = _d.sent();
4640
4643
  if (result == null) {
4641
4644
  msg = field.DisplayName + ' does not exist!';
4642
4645
  }
4643
- _c.label = 23;
4644
- case 23: return [3 /*break*/, 37];
4646
+ _d.label = 23;
4647
+ case 23: return [3 /*break*/, 51];
4645
4648
  case 24:
4646
4649
  if (!Array.isArray(fieldData)) return [3 /*break*/, 32];
4647
4650
  if (!fieldData.length) return [3 /*break*/, 30];
@@ -4650,13 +4653,17 @@ function ValidateUserInput(options) {
4650
4653
  schemaData = [];
4651
4654
  return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
4652
4655
  case 25:
4653
- result = _c.sent();
4654
- if (result && result.Data)
4655
- schemaData = result.Data.filter(function (x) { return fieldData.includes(x.Key.toString()); });
4656
+ result = _d.sent();
4657
+ if (result && result.Data) {
4658
+ if (action == 'add')
4659
+ schemaData = result.Data.filter(function (x) { return x.IsActive == true && fieldData.includes(x.Key.toString()); });
4660
+ else
4661
+ schemaData = result.Data.filter(function (x) { return fieldData.includes(x.Key.toString()); });
4662
+ }
4656
4663
  if (schemaData.length != fieldData.length) {
4657
4664
  msg = field.DisplayName + ' does not exist!';
4658
4665
  }
4659
- _c.label = 26;
4666
+ _d.label = 26;
4660
4667
  case 26: return [3 /*break*/, 29];
4661
4668
  case 27:
4662
4669
  if (!(field.LookupObject !== undefined)) return [3 /*break*/, 29];
@@ -4667,22 +4674,22 @@ function ValidateUserInput(options) {
4667
4674
  ;
4668
4675
  return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
4669
4676
  case 28:
4670
- totalRecord = _c.sent();
4677
+ totalRecord = _d.sent();
4671
4678
  if (totalRecord !== fieldData.length) {
4672
4679
  msg = field.DisplayName + ' does not exist!';
4673
4680
  }
4674
- _c.label = 29;
4681
+ _d.label = 29;
4675
4682
  case 29: return [3 /*break*/, 31];
4676
4683
  case 30:
4677
4684
  if (field.IsRequired) {
4678
4685
  msg = field.DisplayName + ' is required!';
4679
4686
  }
4680
- _c.label = 31;
4687
+ _d.label = 31;
4681
4688
  case 31: return [3 /*break*/, 33];
4682
4689
  case 32:
4683
4690
  msg = 'Invalid value for ' + field.DisplayName;
4684
- _c.label = 33;
4685
- case 33: return [3 /*break*/, 37];
4691
+ _d.label = 33;
4692
+ case 33: return [3 /*break*/, 51];
4686
4693
  case 34:
4687
4694
  {
4688
4695
  regexpression = new RegExp('^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+@,:=#()]*)*(\\?[;&a-z\\d%_@,.:()~+=-]*)?(\\#[-a-z\\d_]*)?$', 'i');
@@ -4690,11 +4697,10 @@ function ValidateUserInput(options) {
4690
4697
  msg = 'Invalid URL for ' + field.DisplayName + '!';
4691
4698
  }
4692
4699
  }
4693
- return [3 /*break*/, 37];
4700
+ return [3 /*break*/, 51];
4694
4701
  case 35:
4695
4702
  {
4696
4703
  if (field.IncludeCountryCode) {
4697
- // phone must begin with '+'
4698
4704
  if (!fieldData.indexOf("+")) {
4699
4705
  phone = phoneUtil.parse(fieldData, "");
4700
4706
  if (!phoneUtil.isValidNumber(phone)) {
@@ -4706,8 +4712,53 @@ function ValidateUserInput(options) {
4706
4712
  }
4707
4713
  }
4708
4714
  }
4709
- return [3 /*break*/, 37];
4715
+ return [3 /*break*/, 51];
4710
4716
  case 36:
4717
+ if (!field.IsMultiple) return [3 /*break*/, 42];
4718
+ if (!Array.isArray(fieldData)) return [3 /*break*/, 40];
4719
+ if (!fieldData.length) return [3 /*break*/, 38];
4720
+ files = [];
4721
+ for (_i = 0, fieldData_1 = fieldData; _i < fieldData_1.length; _i++) {
4722
+ obj = fieldData_1[_i];
4723
+ files.push(obj._id);
4724
+ }
4725
+ searchObj = { _id: { $in: files } };
4726
+ if (action == 'add') {
4727
+ searchObj.IsActive = true;
4728
+ }
4729
+ ;
4730
+ return [4 /*yield*/, db.collection("Drive").find(searchObj).count()];
4731
+ case 37:
4732
+ totalRecord = _d.sent();
4733
+ if (totalRecord !== fieldData.length) {
4734
+ msg = field.DisplayName + ' does not exist!';
4735
+ }
4736
+ return [3 /*break*/, 39];
4737
+ case 38:
4738
+ if (field.IsRequired) {
4739
+ msg = field.DisplayName + ' is required!';
4740
+ }
4741
+ _d.label = 39;
4742
+ case 39: return [3 /*break*/, 41];
4743
+ case 40:
4744
+ msg = 'Invalid value for ' + field.DisplayName;
4745
+ _d.label = 41;
4746
+ case 41: return [3 /*break*/, 44];
4747
+ case 42:
4748
+ searchObj = { _id: fieldData };
4749
+ if (action == 'add') {
4750
+ searchObj.IsActive = true;
4751
+ }
4752
+ ;
4753
+ return [4 /*yield*/, db.collection("Drive").findOne(searchObj)];
4754
+ case 43:
4755
+ result = _d.sent();
4756
+ if (result == null) {
4757
+ msg = field.DisplayName + ' does not exist!';
4758
+ }
4759
+ _d.label = 44;
4760
+ case 44: return [3 /*break*/, 51];
4761
+ case 45:
4711
4762
  {
4712
4763
  // Maxlength check;
4713
4764
  if (field.MaxLength !== undefined && fieldData.length > field.MaxLength) {
@@ -4717,15 +4768,34 @@ function ValidateUserInput(options) {
4717
4768
  msg = 'Invalid value for ' + field.DisplayName;
4718
4769
  }
4719
4770
  }
4720
- return [3 /*break*/, 37];
4721
- case 37: return [3 /*break*/, 39];
4722
- case 38:
4771
+ return [3 /*break*/, 51];
4772
+ case 46:
4773
+ if (!fieldData.length) return [3 /*break*/, 50];
4774
+ _c = 0, fieldData_2 = fieldData;
4775
+ _d.label = 47;
4776
+ case 47:
4777
+ if (!(_c < fieldData_2.length)) return [3 /*break*/, 50];
4778
+ obj = fieldData_2[_c];
4779
+ return [4 /*yield*/, ValidateUserInput({ 'userInput': obj, 'pageData': pageData, 'objectID': documentID, 'db': db, 'collectionField': fieldName })];
4780
+ case 48:
4781
+ validateResp = _d.sent();
4782
+ if (validateResp && validateResp != "") {
4783
+ msg = validateResp;
4784
+ return [3 /*break*/, 50];
4785
+ }
4786
+ _d.label = 49;
4787
+ case 49:
4788
+ _c++;
4789
+ return [3 /*break*/, 47];
4790
+ case 50: return [3 /*break*/, 51];
4791
+ case 51: return [3 /*break*/, 53];
4792
+ case 52:
4723
4793
  if (!IsSystemField(objectName, fieldName) && !IsAnotherObjectField(pageData, fieldName)) {
4724
4794
  msg = fieldName + " is not valid schema!";
4725
4795
  return [2 /*return*/, "break"];
4726
4796
  }
4727
- _c.label = 39;
4728
- case 39: return [2 /*return*/];
4797
+ _d.label = 53;
4798
+ case 53: return [2 /*return*/];
4729
4799
  }
4730
4800
  });
4731
4801
  };
@@ -4743,12 +4813,27 @@ function ValidateUserInput(options) {
4743
4813
  case 3:
4744
4814
  _a++;
4745
4815
  return [3 /*break*/, 1];
4746
- case 4: return [2 /*return*/, msg];
4816
+ case 4:
4817
+ if (msg != "") {
4818
+ return [2 /*return*/, msg];
4819
+ }
4820
+ if (!(objectName == 'City')) return [3 /*break*/, 6];
4821
+ return [4 /*yield*/, db.collection("Country").findOne({ '_id': inputFields.CountryID, 'IsActive': true })];
4747
4822
  case 5:
4823
+ countryData = _b.sent();
4824
+ if (countryData) {
4825
+ inputFields.CountryName = countryData.Name;
4826
+ }
4827
+ else {
4828
+ msg = "Invalid country code!";
4829
+ }
4830
+ _b.label = 6;
4831
+ case 6: return [2 /*return*/, msg];
4832
+ case 7:
4748
4833
  err_3 = _b.sent();
4749
4834
  console.log("Error in ValidateUserInput", err_3);
4750
- return [3 /*break*/, 6];
4751
- case 6: return [2 /*return*/];
4835
+ return [3 /*break*/, 8];
4836
+ case 8: return [2 /*return*/];
4752
4837
  }
4753
4838
  });
4754
4839
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.289",
3
+ "version": "1.0.291",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {