@optimiser/common 1.0.289 → 1.0.290
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 +78 -28
- package/package.json +1 -1
package/dist/lib/utility.js
CHANGED
|
@@ -4458,7 +4458,7 @@ 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;
|
|
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
4462
|
return __generator(this, function (_c) {
|
|
4463
4463
|
switch (_c.label) {
|
|
4464
4464
|
case 0:
|
|
@@ -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*/, 47];
|
|
4472
4472
|
if (fieldData && IsStringValue(fieldData) && field.UIDataType != 'dropdown') {
|
|
4473
4473
|
fieldData = fieldData.trim();
|
|
4474
4474
|
if (["text", "email", "phone"].includes(field.UIDataType)) {
|
|
@@ -4497,8 +4497,8 @@ function ValidateUserInput(options) {
|
|
|
4497
4497
|
}
|
|
4498
4498
|
_c.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*/, 46];
|
|
4501
|
+
if (!(fieldData || fieldData === 0 || fieldData === false)) return [3 /*break*/, 46];
|
|
4502
4502
|
_a = field.UIDataType;
|
|
4503
4503
|
switch (_a) {
|
|
4504
4504
|
case 'int': return [3 /*break*/, 3];
|
|
@@ -4514,11 +4514,13 @@ 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
|
|
4518
|
-
case '
|
|
4519
|
-
case '
|
|
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];
|
|
4520
4522
|
}
|
|
4521
|
-
return [3 /*break*/,
|
|
4523
|
+
return [3 /*break*/, 46];
|
|
4522
4524
|
case 3:
|
|
4523
4525
|
{
|
|
4524
4526
|
if (IsStringValue(fieldData)) {
|
|
@@ -4537,14 +4539,14 @@ function ValidateUserInput(options) {
|
|
|
4537
4539
|
msg = field.DisplayName + ' value must be smaller then or equal to ' + field.MaxValue;
|
|
4538
4540
|
}
|
|
4539
4541
|
}
|
|
4540
|
-
return [3 /*break*/,
|
|
4542
|
+
return [3 /*break*/, 46];
|
|
4541
4543
|
case 4:
|
|
4542
4544
|
{
|
|
4543
4545
|
if ((fieldData instanceof Date && !isNaN(inputFields[fieldName])) == false) {
|
|
4544
4546
|
msg = 'Invalid date for ' + field.DisplayName + '!';
|
|
4545
4547
|
}
|
|
4546
4548
|
}
|
|
4547
|
-
return [3 /*break*/,
|
|
4549
|
+
return [3 /*break*/, 46];
|
|
4548
4550
|
case 5:
|
|
4549
4551
|
{
|
|
4550
4552
|
isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(fieldData);
|
|
@@ -4552,7 +4554,7 @@ function ValidateUserInput(options) {
|
|
|
4552
4554
|
msg = 'Invalid time for ' + field.DisplayName + '!';
|
|
4553
4555
|
}
|
|
4554
4556
|
}
|
|
4555
|
-
return [3 /*break*/,
|
|
4557
|
+
return [3 /*break*/, 46];
|
|
4556
4558
|
case 6:
|
|
4557
4559
|
{
|
|
4558
4560
|
filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
|
|
@@ -4560,14 +4562,14 @@ function ValidateUserInput(options) {
|
|
|
4560
4562
|
msg = 'Invalid email for ' + field.DisplayName + '!';
|
|
4561
4563
|
}
|
|
4562
4564
|
}
|
|
4563
|
-
return [3 /*break*/,
|
|
4565
|
+
return [3 /*break*/, 46];
|
|
4564
4566
|
case 7:
|
|
4565
4567
|
{
|
|
4566
4568
|
if (fieldData !== true && fieldData !== false) {
|
|
4567
4569
|
msg = 'Invalid user input for ' + field.DisplayName + '!';
|
|
4568
4570
|
}
|
|
4569
4571
|
}
|
|
4570
|
-
return [3 /*break*/,
|
|
4572
|
+
return [3 /*break*/, 46];
|
|
4571
4573
|
case 8:
|
|
4572
4574
|
searchObj = { _id: fieldData };
|
|
4573
4575
|
if (action == 'add') {
|
|
@@ -4580,7 +4582,7 @@ function ValidateUserInput(options) {
|
|
|
4580
4582
|
if (result == null) {
|
|
4581
4583
|
msg = field.DisplayName + ' does not exist!';
|
|
4582
4584
|
}
|
|
4583
|
-
return [3 /*break*/,
|
|
4585
|
+
return [3 /*break*/, 46];
|
|
4584
4586
|
case 10:
|
|
4585
4587
|
if (!Array.isArray(fieldData)) return [3 /*break*/, 16];
|
|
4586
4588
|
if (!fieldData.length) return [3 /*break*/, 14];
|
|
@@ -4612,7 +4614,7 @@ function ValidateUserInput(options) {
|
|
|
4612
4614
|
case 16:
|
|
4613
4615
|
msg = 'Invalid value for ' + field.DisplayName;
|
|
4614
4616
|
_c.label = 17;
|
|
4615
|
-
case 17: return [3 /*break*/,
|
|
4617
|
+
case 17: return [3 /*break*/, 46];
|
|
4616
4618
|
case 18:
|
|
4617
4619
|
if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 21];
|
|
4618
4620
|
if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 20];
|
|
@@ -4622,7 +4624,7 @@ function ValidateUserInput(options) {
|
|
|
4622
4624
|
result = _c.sent();
|
|
4623
4625
|
if (result && result.Data)
|
|
4624
4626
|
schemaData = result.Data.find(function (x) { return x.Key == fieldData; });
|
|
4625
|
-
if (schemaData == null) {
|
|
4627
|
+
if (schemaData == null || (action == 'add' && schemaData.IsActive == false)) {
|
|
4626
4628
|
msg = field.DisplayName + ' does not exist!';
|
|
4627
4629
|
}
|
|
4628
4630
|
_c.label = 20;
|
|
@@ -4641,7 +4643,7 @@ function ValidateUserInput(options) {
|
|
|
4641
4643
|
msg = field.DisplayName + ' does not exist!';
|
|
4642
4644
|
}
|
|
4643
4645
|
_c.label = 23;
|
|
4644
|
-
case 23: return [3 /*break*/,
|
|
4646
|
+
case 23: return [3 /*break*/, 46];
|
|
4645
4647
|
case 24:
|
|
4646
4648
|
if (!Array.isArray(fieldData)) return [3 /*break*/, 32];
|
|
4647
4649
|
if (!fieldData.length) return [3 /*break*/, 30];
|
|
@@ -4651,8 +4653,12 @@ function ValidateUserInput(options) {
|
|
|
4651
4653
|
return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
|
|
4652
4654
|
case 25:
|
|
4653
4655
|
result = _c.sent();
|
|
4654
|
-
if (result && result.Data)
|
|
4655
|
-
|
|
4656
|
+
if (result && result.Data) {
|
|
4657
|
+
if (action == 'add')
|
|
4658
|
+
schemaData = result.Data.filter(function (x) { return x.IsActive == true && fieldData.includes(x.Key.toString()); });
|
|
4659
|
+
else
|
|
4660
|
+
schemaData = result.Data.filter(function (x) { return fieldData.includes(x.Key.toString()); });
|
|
4661
|
+
}
|
|
4656
4662
|
if (schemaData.length != fieldData.length) {
|
|
4657
4663
|
msg = field.DisplayName + ' does not exist!';
|
|
4658
4664
|
}
|
|
@@ -4682,7 +4688,7 @@ function ValidateUserInput(options) {
|
|
|
4682
4688
|
case 32:
|
|
4683
4689
|
msg = 'Invalid value for ' + field.DisplayName;
|
|
4684
4690
|
_c.label = 33;
|
|
4685
|
-
case 33: return [3 /*break*/,
|
|
4691
|
+
case 33: return [3 /*break*/, 46];
|
|
4686
4692
|
case 34:
|
|
4687
4693
|
{
|
|
4688
4694
|
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 +4696,10 @@ function ValidateUserInput(options) {
|
|
|
4690
4696
|
msg = 'Invalid URL for ' + field.DisplayName + '!';
|
|
4691
4697
|
}
|
|
4692
4698
|
}
|
|
4693
|
-
return [3 /*break*/,
|
|
4699
|
+
return [3 /*break*/, 46];
|
|
4694
4700
|
case 35:
|
|
4695
4701
|
{
|
|
4696
4702
|
if (field.IncludeCountryCode) {
|
|
4697
|
-
// phone must begin with '+'
|
|
4698
4703
|
if (!fieldData.indexOf("+")) {
|
|
4699
4704
|
phone = phoneUtil.parse(fieldData, "");
|
|
4700
4705
|
if (!phoneUtil.isValidNumber(phone)) {
|
|
@@ -4706,8 +4711,53 @@ function ValidateUserInput(options) {
|
|
|
4706
4711
|
}
|
|
4707
4712
|
}
|
|
4708
4713
|
}
|
|
4709
|
-
return [3 /*break*/,
|
|
4714
|
+
return [3 /*break*/, 46];
|
|
4710
4715
|
case 36:
|
|
4716
|
+
if (!field.IsMultiple) return [3 /*break*/, 42];
|
|
4717
|
+
if (!Array.isArray(fieldData)) return [3 /*break*/, 40];
|
|
4718
|
+
if (!fieldData.length) return [3 /*break*/, 38];
|
|
4719
|
+
files = [];
|
|
4720
|
+
for (_i = 0, fieldData_1 = fieldData; _i < fieldData_1.length; _i++) {
|
|
4721
|
+
obj = fieldData_1[_i];
|
|
4722
|
+
files.push(obj._id);
|
|
4723
|
+
}
|
|
4724
|
+
searchObj = { _id: { $in: files } };
|
|
4725
|
+
if (action == 'add') {
|
|
4726
|
+
searchObj.IsActive = true;
|
|
4727
|
+
}
|
|
4728
|
+
;
|
|
4729
|
+
return [4 /*yield*/, db.collection("Drive").find(searchObj).count()];
|
|
4730
|
+
case 37:
|
|
4731
|
+
totalRecord = _c.sent();
|
|
4732
|
+
if (totalRecord !== fieldData.length) {
|
|
4733
|
+
msg = field.DisplayName + ' does not exist!';
|
|
4734
|
+
}
|
|
4735
|
+
return [3 /*break*/, 39];
|
|
4736
|
+
case 38:
|
|
4737
|
+
if (field.IsRequired) {
|
|
4738
|
+
msg = field.DisplayName + ' is required!';
|
|
4739
|
+
}
|
|
4740
|
+
_c.label = 39;
|
|
4741
|
+
case 39: return [3 /*break*/, 41];
|
|
4742
|
+
case 40:
|
|
4743
|
+
msg = 'Invalid value for ' + field.DisplayName;
|
|
4744
|
+
_c.label = 41;
|
|
4745
|
+
case 41: return [3 /*break*/, 44];
|
|
4746
|
+
case 42:
|
|
4747
|
+
searchObj = { _id: fieldData };
|
|
4748
|
+
if (action == 'add') {
|
|
4749
|
+
searchObj.IsActive = true;
|
|
4750
|
+
}
|
|
4751
|
+
;
|
|
4752
|
+
return [4 /*yield*/, db.collection("Drive").findOne(searchObj)];
|
|
4753
|
+
case 43:
|
|
4754
|
+
result = _c.sent();
|
|
4755
|
+
if (result == null) {
|
|
4756
|
+
msg = field.DisplayName + ' does not exist!';
|
|
4757
|
+
}
|
|
4758
|
+
_c.label = 44;
|
|
4759
|
+
case 44: return [3 /*break*/, 46];
|
|
4760
|
+
case 45:
|
|
4711
4761
|
{
|
|
4712
4762
|
// Maxlength check;
|
|
4713
4763
|
if (field.MaxLength !== undefined && fieldData.length > field.MaxLength) {
|
|
@@ -4717,15 +4767,15 @@ function ValidateUserInput(options) {
|
|
|
4717
4767
|
msg = 'Invalid value for ' + field.DisplayName;
|
|
4718
4768
|
}
|
|
4719
4769
|
}
|
|
4720
|
-
return [3 /*break*/,
|
|
4721
|
-
case
|
|
4722
|
-
case
|
|
4770
|
+
return [3 /*break*/, 46];
|
|
4771
|
+
case 46: return [3 /*break*/, 48];
|
|
4772
|
+
case 47:
|
|
4723
4773
|
if (!IsSystemField(objectName, fieldName) && !IsAnotherObjectField(pageData, fieldName)) {
|
|
4724
4774
|
msg = fieldName + " is not valid schema!";
|
|
4725
4775
|
return [2 /*return*/, "break"];
|
|
4726
4776
|
}
|
|
4727
|
-
_c.label =
|
|
4728
|
-
case
|
|
4777
|
+
_c.label = 48;
|
|
4778
|
+
case 48: return [2 /*return*/];
|
|
4729
4779
|
}
|
|
4730
4780
|
});
|
|
4731
4781
|
};
|