@optimiser/common 1.0.290 → 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.
- package/dist/lib/utility.js +86 -51
- package/package.json +1 -1
package/dist/lib/utility.js
CHANGED
|
@@ -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,
|
|
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, files, _i, fieldData_1, obj, searchObj, totalRecord, searchObj, result;
|
|
4462
|
-
return __generator(this, function (
|
|
4463
|
-
switch (
|
|
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*/,
|
|
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 =
|
|
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
|
-
|
|
4498
|
+
_d.label = 2;
|
|
4499
4499
|
case 2:
|
|
4500
|
-
if (!inputField.includes(fieldName)) return [3 /*break*/,
|
|
4501
|
-
if (!(fieldData || fieldData === 0 || fieldData === false)) return [3 /*break*/,
|
|
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];
|
|
@@ -4519,8 +4519,9 @@ function ValidateUserInput(options) {
|
|
|
4519
4519
|
case 'textarea': return [3 /*break*/, 45];
|
|
4520
4520
|
case 'text': return [3 /*break*/, 45];
|
|
4521
4521
|
case 'texteditor': return [3 /*break*/, 45];
|
|
4522
|
+
case 'collection': return [3 /*break*/, 46];
|
|
4522
4523
|
}
|
|
4523
|
-
return [3 /*break*/,
|
|
4524
|
+
return [3 /*break*/, 51];
|
|
4524
4525
|
case 3:
|
|
4525
4526
|
{
|
|
4526
4527
|
if (IsStringValue(fieldData)) {
|
|
@@ -4539,14 +4540,14 @@ function ValidateUserInput(options) {
|
|
|
4539
4540
|
msg = field.DisplayName + ' value must be smaller then or equal to ' + field.MaxValue;
|
|
4540
4541
|
}
|
|
4541
4542
|
}
|
|
4542
|
-
return [3 /*break*/,
|
|
4543
|
+
return [3 /*break*/, 51];
|
|
4543
4544
|
case 4:
|
|
4544
4545
|
{
|
|
4545
4546
|
if ((fieldData instanceof Date && !isNaN(inputFields[fieldName])) == false) {
|
|
4546
4547
|
msg = 'Invalid date for ' + field.DisplayName + '!';
|
|
4547
4548
|
}
|
|
4548
4549
|
}
|
|
4549
|
-
return [3 /*break*/,
|
|
4550
|
+
return [3 /*break*/, 51];
|
|
4550
4551
|
case 5:
|
|
4551
4552
|
{
|
|
4552
4553
|
isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(fieldData);
|
|
@@ -4554,7 +4555,7 @@ function ValidateUserInput(options) {
|
|
|
4554
4555
|
msg = 'Invalid time for ' + field.DisplayName + '!';
|
|
4555
4556
|
}
|
|
4556
4557
|
}
|
|
4557
|
-
return [3 /*break*/,
|
|
4558
|
+
return [3 /*break*/, 51];
|
|
4558
4559
|
case 6:
|
|
4559
4560
|
{
|
|
4560
4561
|
filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
|
|
@@ -4562,14 +4563,14 @@ function ValidateUserInput(options) {
|
|
|
4562
4563
|
msg = 'Invalid email for ' + field.DisplayName + '!';
|
|
4563
4564
|
}
|
|
4564
4565
|
}
|
|
4565
|
-
return [3 /*break*/,
|
|
4566
|
+
return [3 /*break*/, 51];
|
|
4566
4567
|
case 7:
|
|
4567
4568
|
{
|
|
4568
4569
|
if (fieldData !== true && fieldData !== false) {
|
|
4569
4570
|
msg = 'Invalid user input for ' + field.DisplayName + '!';
|
|
4570
4571
|
}
|
|
4571
4572
|
}
|
|
4572
|
-
return [3 /*break*/,
|
|
4573
|
+
return [3 /*break*/, 51];
|
|
4573
4574
|
case 8:
|
|
4574
4575
|
searchObj = { _id: fieldData };
|
|
4575
4576
|
if (action == 'add') {
|
|
@@ -4578,11 +4579,11 @@ function ValidateUserInput(options) {
|
|
|
4578
4579
|
;
|
|
4579
4580
|
return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
|
|
4580
4581
|
case 9:
|
|
4581
|
-
result =
|
|
4582
|
+
result = _d.sent();
|
|
4582
4583
|
if (result == null) {
|
|
4583
4584
|
msg = field.DisplayName + ' does not exist!';
|
|
4584
4585
|
}
|
|
4585
|
-
return [3 /*break*/,
|
|
4586
|
+
return [3 /*break*/, 51];
|
|
4586
4587
|
case 10:
|
|
4587
4588
|
if (!Array.isArray(fieldData)) return [3 /*break*/, 16];
|
|
4588
4589
|
if (!fieldData.length) return [3 /*break*/, 14];
|
|
@@ -4593,13 +4594,13 @@ function ValidateUserInput(options) {
|
|
|
4593
4594
|
;
|
|
4594
4595
|
return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
|
|
4595
4596
|
case 11:
|
|
4596
|
-
totalRecord =
|
|
4597
|
+
totalRecord = _d.sent();
|
|
4597
4598
|
if (!(objectName == "Activity" && field.Name == 'Attendees')) return [3 /*break*/, 13];
|
|
4598
4599
|
_b = totalRecord;
|
|
4599
4600
|
return [4 /*yield*/, db.collection('Contact').find(searchObj).count()];
|
|
4600
4601
|
case 12:
|
|
4601
|
-
totalRecord = _b +
|
|
4602
|
-
|
|
4602
|
+
totalRecord = _b + _d.sent();
|
|
4603
|
+
_d.label = 13;
|
|
4603
4604
|
case 13:
|
|
4604
4605
|
if (totalRecord !== fieldData.length) {
|
|
4605
4606
|
msg = field.DisplayName + ' does not exist!';
|
|
@@ -4609,25 +4610,25 @@ function ValidateUserInput(options) {
|
|
|
4609
4610
|
if (field.IsRequired) {
|
|
4610
4611
|
msg = field.DisplayName + ' is required!';
|
|
4611
4612
|
}
|
|
4612
|
-
|
|
4613
|
+
_d.label = 15;
|
|
4613
4614
|
case 15: return [3 /*break*/, 17];
|
|
4614
4615
|
case 16:
|
|
4615
4616
|
msg = 'Invalid value for ' + field.DisplayName;
|
|
4616
|
-
|
|
4617
|
-
case 17: return [3 /*break*/,
|
|
4617
|
+
_d.label = 17;
|
|
4618
|
+
case 17: return [3 /*break*/, 51];
|
|
4618
4619
|
case 18:
|
|
4619
4620
|
if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 21];
|
|
4620
4621
|
if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 20];
|
|
4621
4622
|
schemaData = null;
|
|
4622
4623
|
return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
|
|
4623
4624
|
case 19:
|
|
4624
|
-
result =
|
|
4625
|
+
result = _d.sent();
|
|
4625
4626
|
if (result && result.Data)
|
|
4626
4627
|
schemaData = result.Data.find(function (x) { return x.Key == fieldData; });
|
|
4627
4628
|
if (schemaData == null || (action == 'add' && schemaData.IsActive == false)) {
|
|
4628
4629
|
msg = field.DisplayName + ' does not exist!';
|
|
4629
4630
|
}
|
|
4630
|
-
|
|
4631
|
+
_d.label = 20;
|
|
4631
4632
|
case 20: return [3 /*break*/, 23];
|
|
4632
4633
|
case 21:
|
|
4633
4634
|
if (!(field.LookupObject !== undefined)) return [3 /*break*/, 23];
|
|
@@ -4638,12 +4639,12 @@ function ValidateUserInput(options) {
|
|
|
4638
4639
|
;
|
|
4639
4640
|
return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
|
|
4640
4641
|
case 22:
|
|
4641
|
-
result =
|
|
4642
|
+
result = _d.sent();
|
|
4642
4643
|
if (result == null) {
|
|
4643
4644
|
msg = field.DisplayName + ' does not exist!';
|
|
4644
4645
|
}
|
|
4645
|
-
|
|
4646
|
-
case 23: return [3 /*break*/,
|
|
4646
|
+
_d.label = 23;
|
|
4647
|
+
case 23: return [3 /*break*/, 51];
|
|
4647
4648
|
case 24:
|
|
4648
4649
|
if (!Array.isArray(fieldData)) return [3 /*break*/, 32];
|
|
4649
4650
|
if (!fieldData.length) return [3 /*break*/, 30];
|
|
@@ -4652,7 +4653,7 @@ function ValidateUserInput(options) {
|
|
|
4652
4653
|
schemaData = [];
|
|
4653
4654
|
return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
|
|
4654
4655
|
case 25:
|
|
4655
|
-
result =
|
|
4656
|
+
result = _d.sent();
|
|
4656
4657
|
if (result && result.Data) {
|
|
4657
4658
|
if (action == 'add')
|
|
4658
4659
|
schemaData = result.Data.filter(function (x) { return x.IsActive == true && fieldData.includes(x.Key.toString()); });
|
|
@@ -4662,7 +4663,7 @@ function ValidateUserInput(options) {
|
|
|
4662
4663
|
if (schemaData.length != fieldData.length) {
|
|
4663
4664
|
msg = field.DisplayName + ' does not exist!';
|
|
4664
4665
|
}
|
|
4665
|
-
|
|
4666
|
+
_d.label = 26;
|
|
4666
4667
|
case 26: return [3 /*break*/, 29];
|
|
4667
4668
|
case 27:
|
|
4668
4669
|
if (!(field.LookupObject !== undefined)) return [3 /*break*/, 29];
|
|
@@ -4673,22 +4674,22 @@ function ValidateUserInput(options) {
|
|
|
4673
4674
|
;
|
|
4674
4675
|
return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
|
|
4675
4676
|
case 28:
|
|
4676
|
-
totalRecord =
|
|
4677
|
+
totalRecord = _d.sent();
|
|
4677
4678
|
if (totalRecord !== fieldData.length) {
|
|
4678
4679
|
msg = field.DisplayName + ' does not exist!';
|
|
4679
4680
|
}
|
|
4680
|
-
|
|
4681
|
+
_d.label = 29;
|
|
4681
4682
|
case 29: return [3 /*break*/, 31];
|
|
4682
4683
|
case 30:
|
|
4683
4684
|
if (field.IsRequired) {
|
|
4684
4685
|
msg = field.DisplayName + ' is required!';
|
|
4685
4686
|
}
|
|
4686
|
-
|
|
4687
|
+
_d.label = 31;
|
|
4687
4688
|
case 31: return [3 /*break*/, 33];
|
|
4688
4689
|
case 32:
|
|
4689
4690
|
msg = 'Invalid value for ' + field.DisplayName;
|
|
4690
|
-
|
|
4691
|
-
case 33: return [3 /*break*/,
|
|
4691
|
+
_d.label = 33;
|
|
4692
|
+
case 33: return [3 /*break*/, 51];
|
|
4692
4693
|
case 34:
|
|
4693
4694
|
{
|
|
4694
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');
|
|
@@ -4696,7 +4697,7 @@ function ValidateUserInput(options) {
|
|
|
4696
4697
|
msg = 'Invalid URL for ' + field.DisplayName + '!';
|
|
4697
4698
|
}
|
|
4698
4699
|
}
|
|
4699
|
-
return [3 /*break*/,
|
|
4700
|
+
return [3 /*break*/, 51];
|
|
4700
4701
|
case 35:
|
|
4701
4702
|
{
|
|
4702
4703
|
if (field.IncludeCountryCode) {
|
|
@@ -4711,7 +4712,7 @@ function ValidateUserInput(options) {
|
|
|
4711
4712
|
}
|
|
4712
4713
|
}
|
|
4713
4714
|
}
|
|
4714
|
-
return [3 /*break*/,
|
|
4715
|
+
return [3 /*break*/, 51];
|
|
4715
4716
|
case 36:
|
|
4716
4717
|
if (!field.IsMultiple) return [3 /*break*/, 42];
|
|
4717
4718
|
if (!Array.isArray(fieldData)) return [3 /*break*/, 40];
|
|
@@ -4728,7 +4729,7 @@ function ValidateUserInput(options) {
|
|
|
4728
4729
|
;
|
|
4729
4730
|
return [4 /*yield*/, db.collection("Drive").find(searchObj).count()];
|
|
4730
4731
|
case 37:
|
|
4731
|
-
totalRecord =
|
|
4732
|
+
totalRecord = _d.sent();
|
|
4732
4733
|
if (totalRecord !== fieldData.length) {
|
|
4733
4734
|
msg = field.DisplayName + ' does not exist!';
|
|
4734
4735
|
}
|
|
@@ -4737,11 +4738,11 @@ function ValidateUserInput(options) {
|
|
|
4737
4738
|
if (field.IsRequired) {
|
|
4738
4739
|
msg = field.DisplayName + ' is required!';
|
|
4739
4740
|
}
|
|
4740
|
-
|
|
4741
|
+
_d.label = 39;
|
|
4741
4742
|
case 39: return [3 /*break*/, 41];
|
|
4742
4743
|
case 40:
|
|
4743
4744
|
msg = 'Invalid value for ' + field.DisplayName;
|
|
4744
|
-
|
|
4745
|
+
_d.label = 41;
|
|
4745
4746
|
case 41: return [3 /*break*/, 44];
|
|
4746
4747
|
case 42:
|
|
4747
4748
|
searchObj = { _id: fieldData };
|
|
@@ -4751,12 +4752,12 @@ function ValidateUserInput(options) {
|
|
|
4751
4752
|
;
|
|
4752
4753
|
return [4 /*yield*/, db.collection("Drive").findOne(searchObj)];
|
|
4753
4754
|
case 43:
|
|
4754
|
-
result =
|
|
4755
|
+
result = _d.sent();
|
|
4755
4756
|
if (result == null) {
|
|
4756
4757
|
msg = field.DisplayName + ' does not exist!';
|
|
4757
4758
|
}
|
|
4758
|
-
|
|
4759
|
-
case 44: return [3 /*break*/,
|
|
4759
|
+
_d.label = 44;
|
|
4760
|
+
case 44: return [3 /*break*/, 51];
|
|
4760
4761
|
case 45:
|
|
4761
4762
|
{
|
|
4762
4763
|
// Maxlength check;
|
|
@@ -4767,15 +4768,34 @@ function ValidateUserInput(options) {
|
|
|
4767
4768
|
msg = 'Invalid value for ' + field.DisplayName;
|
|
4768
4769
|
}
|
|
4769
4770
|
}
|
|
4770
|
-
return [3 /*break*/,
|
|
4771
|
-
case 46:
|
|
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;
|
|
4772
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:
|
|
4773
4793
|
if (!IsSystemField(objectName, fieldName) && !IsAnotherObjectField(pageData, fieldName)) {
|
|
4774
4794
|
msg = fieldName + " is not valid schema!";
|
|
4775
4795
|
return [2 /*return*/, "break"];
|
|
4776
4796
|
}
|
|
4777
|
-
|
|
4778
|
-
case
|
|
4797
|
+
_d.label = 53;
|
|
4798
|
+
case 53: return [2 /*return*/];
|
|
4779
4799
|
}
|
|
4780
4800
|
});
|
|
4781
4801
|
};
|
|
@@ -4793,12 +4813,27 @@ function ValidateUserInput(options) {
|
|
|
4793
4813
|
case 3:
|
|
4794
4814
|
_a++;
|
|
4795
4815
|
return [3 /*break*/, 1];
|
|
4796
|
-
case 4:
|
|
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 })];
|
|
4797
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:
|
|
4798
4833
|
err_3 = _b.sent();
|
|
4799
4834
|
console.log("Error in ValidateUserInput", err_3);
|
|
4800
|
-
return [3 /*break*/,
|
|
4801
|
-
case
|
|
4835
|
+
return [3 /*break*/, 8];
|
|
4836
|
+
case 8: return [2 /*return*/];
|
|
4802
4837
|
}
|
|
4803
4838
|
});
|
|
4804
4839
|
});
|