@optimiser/common 1.0.338 → 1.0.339
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 +285 -267
- package/package.json +1 -1
package/dist/lib/utility.js
CHANGED
|
@@ -1503,275 +1503,293 @@ function GetObjectByString(o, s) {
|
|
|
1503
1503
|
exports.GetObjectByString = GetObjectByString;
|
|
1504
1504
|
//Build _LookupDataField before save
|
|
1505
1505
|
function BuildLookupDataField(fieldSchema, updateObj, db) {
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
lookupObj["let"] = { 'fld': '$' + obj.localField };
|
|
1539
|
-
lookupObj["pipeline"] = [{ "$match": { "$expr": { "$eq": ["$_id", "$$fld"] } } }];
|
|
1540
|
-
lookupObj["as"] = obj.as;
|
|
1541
|
-
aggregateArry.push({ $lookup: lookupObj });
|
|
1542
|
-
aggregateArry.push({ $unwind: { path: '$' + obj.as, preserveNullAndEmptyArrays: true } });
|
|
1543
|
-
project[obj.as + '._id'] = 1;
|
|
1544
|
-
project[obj.as + '.IsActive'] = 1;
|
|
1506
|
+
var _a, _b;
|
|
1507
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1508
|
+
var fldValue, fldName, alias, searchAlias, fldLookupData, aggregateArry, project, i, obj, lookupObj, i, i, data, _c, result, _loop_10, j, i, unionDetail, unionPipeline, unionObj, result, i, lookupRecord, j, result, j, result, i, lookupRecord, j, result, i, lookupRecord, error_2, fieldValueType, errMsg;
|
|
1509
|
+
return __generator(this, function (_d) {
|
|
1510
|
+
switch (_d.label) {
|
|
1511
|
+
case 0:
|
|
1512
|
+
fldValue = null;
|
|
1513
|
+
_d.label = 1;
|
|
1514
|
+
case 1:
|
|
1515
|
+
_d.trys.push([1, 23, , 24]);
|
|
1516
|
+
if (!(fieldSchema.UIDataType && constants_1.default.LookupTypeFields.includes(fieldSchema.UIDataType))) return [3 /*break*/, 22];
|
|
1517
|
+
fldName = fieldSchema.Name;
|
|
1518
|
+
fldValue = updateObj[fldName];
|
|
1519
|
+
alias = fldName + constants_1.default.LookupAlias;
|
|
1520
|
+
searchAlias = fldName + constants_1.default.SearchValueAlias;
|
|
1521
|
+
fldLookupData = null;
|
|
1522
|
+
if (!fldValue) return [3 /*break*/, 21];
|
|
1523
|
+
aggregateArry = [];
|
|
1524
|
+
project = { '_id': 1, IsActive: 1 };
|
|
1525
|
+
if (fieldSchema.ExtraLookupObjects) {
|
|
1526
|
+
for (i = 0; i < fieldSchema.ExtraLookupObjects.length; i++) {
|
|
1527
|
+
obj = fieldSchema.ExtraLookupObjects[i];
|
|
1528
|
+
lookupObj = {};
|
|
1529
|
+
lookupObj["from"] = obj.from;
|
|
1530
|
+
lookupObj["let"] = { 'fld': '$' + obj.localField };
|
|
1531
|
+
lookupObj["pipeline"] = [{ "$match": { "$expr": { "$eq": ["$_id", "$$fld"] } } }];
|
|
1532
|
+
lookupObj["as"] = obj.as;
|
|
1533
|
+
aggregateArry.push({ $lookup: lookupObj });
|
|
1534
|
+
aggregateArry.push({ $unwind: { path: '$' + obj.as, preserveNullAndEmptyArrays: true } });
|
|
1535
|
+
project[obj.as + '._id'] = 1;
|
|
1536
|
+
project[obj.as + '.IsActive'] = 1;
|
|
1537
|
+
}
|
|
1545
1538
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1539
|
+
if (fieldSchema.LookupFields != undefined) {
|
|
1540
|
+
for (i = 0; i < fieldSchema.LookupFields.length; i++) {
|
|
1541
|
+
project[fieldSchema.LookupFields[i]] = 1;
|
|
1542
|
+
}
|
|
1543
|
+
;
|
|
1550
1544
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1545
|
+
if (fieldSchema.ExtraLookupFields != undefined) {
|
|
1546
|
+
for (i = 0; i < fieldSchema.ExtraLookupFields.length; i++) {
|
|
1547
|
+
project[fieldSchema.ExtraLookupFields[i]] = 1;
|
|
1548
|
+
}
|
|
1549
|
+
;
|
|
1556
1550
|
}
|
|
1557
|
-
;
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
resolve();
|
|
1588
|
-
});
|
|
1589
|
-
break;
|
|
1590
|
-
case "multilookup":
|
|
1591
|
-
aggregateArry.push({ $match: { '_id': { $in: fldValue_1 } } });
|
|
1592
|
-
aggregateArry.push({ $project: project });
|
|
1593
|
-
if (fieldSchema.UnionWith && fieldSchema.UnionWith.length > 0) {
|
|
1594
|
-
for (var i = 0; i < fieldSchema.UnionWith.length; i++) {
|
|
1595
|
-
var unionDetail = fieldSchema.UnionWith[i];
|
|
1596
|
-
if (unionDetail) {
|
|
1597
|
-
var unionPipeline = [];
|
|
1598
|
-
unionPipeline.push({
|
|
1599
|
-
$match: { '_id': { $in: fldValue_1 } }
|
|
1600
|
-
});
|
|
1601
|
-
unionPipeline.push({ $project: project });
|
|
1602
|
-
var unionObj = { coll: unionDetail.LookupObject, pipeline: unionPipeline };
|
|
1603
|
-
aggregateArry.push({ $unionWith: unionObj });
|
|
1551
|
+
data = null;
|
|
1552
|
+
_c = fieldSchema.UIDataType;
|
|
1553
|
+
switch (_c) {
|
|
1554
|
+
case "lookup": return [3 /*break*/, 2];
|
|
1555
|
+
case "multilookup": return [3 /*break*/, 4];
|
|
1556
|
+
case "dropdown": return [3 /*break*/, 6];
|
|
1557
|
+
case "multiselect": return [3 /*break*/, 11];
|
|
1558
|
+
case "file": return [3 /*break*/, 16];
|
|
1559
|
+
case "image": return [3 /*break*/, 16];
|
|
1560
|
+
}
|
|
1561
|
+
return [3 /*break*/, 19];
|
|
1562
|
+
case 2:
|
|
1563
|
+
aggregateArry.push({ $match: { '_id': fldValue } });
|
|
1564
|
+
aggregateArry.push({ $project: project });
|
|
1565
|
+
return [4 /*yield*/, db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray()];
|
|
1566
|
+
case 3:
|
|
1567
|
+
// db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
|
|
1568
|
+
data = _d.sent();
|
|
1569
|
+
// if (err) {
|
|
1570
|
+
// errorHandler(fldValue, err);
|
|
1571
|
+
// }
|
|
1572
|
+
// else
|
|
1573
|
+
if (data && data.length > 0) {
|
|
1574
|
+
fldLookupData = data[0];
|
|
1575
|
+
updateObj[alias] = fldLookupData;
|
|
1576
|
+
result = '';
|
|
1577
|
+
if (fieldSchema.LookupFields != undefined) {
|
|
1578
|
+
_loop_10 = function (j) {
|
|
1579
|
+
if (fieldSchema.ExcludeLookupFieldsOnSearch && fieldSchema.ExcludeLookupFieldsOnSearch.filter(function (x) { return x == fieldSchema.LookupFields[j]; }).length != 0) {
|
|
1580
|
+
return "continue";
|
|
1604
1581
|
}
|
|
1582
|
+
if (GetObjectByString(fldLookupData, fieldSchema.LookupFields[j]) != undefined)
|
|
1583
|
+
result += GetObjectByString(fldLookupData, fieldSchema.LookupFields[j]).toString() + ' ';
|
|
1584
|
+
};
|
|
1585
|
+
for (j = 0; j < fieldSchema.LookupFields.length; j++) {
|
|
1586
|
+
_loop_10(j);
|
|
1605
1587
|
}
|
|
1606
1588
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1589
|
+
updateObj[searchAlias] = result === null || result === void 0 ? void 0 : result.trim();
|
|
1590
|
+
//** Ends here */
|
|
1591
|
+
}
|
|
1592
|
+
// resolve()
|
|
1593
|
+
// });
|
|
1594
|
+
return [3 /*break*/, 20];
|
|
1595
|
+
case 4:
|
|
1596
|
+
aggregateArry.push({ $match: { '_id': { $in: fldValue } } });
|
|
1597
|
+
aggregateArry.push({ $project: project });
|
|
1598
|
+
if (fieldSchema.UnionWith && fieldSchema.UnionWith.length > 0) {
|
|
1599
|
+
for (i = 0; i < fieldSchema.UnionWith.length; i++) {
|
|
1600
|
+
unionDetail = fieldSchema.UnionWith[i];
|
|
1601
|
+
if (unionDetail) {
|
|
1602
|
+
unionPipeline = [];
|
|
1603
|
+
unionPipeline.push({
|
|
1604
|
+
$match: { '_id': { $in: fldValue } }
|
|
1605
|
+
});
|
|
1606
|
+
unionPipeline.push({ $project: project });
|
|
1607
|
+
unionObj = { coll: unionDetail.LookupObject, pipeline: unionPipeline };
|
|
1608
|
+
aggregateArry.push({ $unionWith: unionObj });
|
|
1611
1609
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return [4 /*yield*/, db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray()];
|
|
1613
|
+
case 5:
|
|
1614
|
+
// db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
|
|
1615
|
+
data = _d.sent();
|
|
1616
|
+
// if (err) {
|
|
1617
|
+
// // throw new Error(err.toString());
|
|
1618
|
+
// errorHandler(fldValue, err);
|
|
1619
|
+
// } else
|
|
1620
|
+
if (data && data.length > 0) {
|
|
1621
|
+
fldLookupData = data;
|
|
1622
|
+
updateObj[alias] = fldLookupData;
|
|
1623
|
+
result = '';
|
|
1624
|
+
for (i = 0; i < data.length; i++) {
|
|
1625
|
+
lookupRecord = data[i];
|
|
1626
|
+
if (fieldSchema.LookupFields != undefined) {
|
|
1627
|
+
for (j = 0; j < fieldSchema.LookupFields.length; j++) {
|
|
1628
|
+
if (GetObjectByString(lookupRecord, fieldSchema.LookupFields[j]) != undefined)
|
|
1629
|
+
result += GetObjectByString(lookupRecord, fieldSchema.LookupFields[j]).toString() + ' ';
|
|
1625
1630
|
}
|
|
1626
|
-
updateObj[searchAlias_1] = result === null || result === void 0 ? void 0 : result.trim();
|
|
1627
|
-
//** Ends here */
|
|
1628
1631
|
}
|
|
1629
|
-
resolve();
|
|
1630
|
-
});
|
|
1631
|
-
break;
|
|
1632
|
-
case "dropdown":
|
|
1633
|
-
if (fieldSchema.LookupObject) {
|
|
1634
|
-
aggregateArry.push({ $match: { _id: fldValue_1 } });
|
|
1635
|
-
aggregateArry.push({ $project: project });
|
|
1636
|
-
db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err, data) {
|
|
1637
|
-
if (err) {
|
|
1638
|
-
errorHandler(fldValue_1, err);
|
|
1639
|
-
}
|
|
1640
|
-
else if (data && data.length > 0) {
|
|
1641
|
-
fldLookupData_1 = data[0];
|
|
1642
|
-
updateObj[alias_1] = fldLookupData_1;
|
|
1643
|
-
//** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
|
|
1644
|
-
var result = '';
|
|
1645
|
-
if (fieldSchema.LookupFields != undefined) {
|
|
1646
|
-
for (var j = 0; j < fieldSchema.LookupFields.length; j++) {
|
|
1647
|
-
if (GetObjectByString(fldLookupData_1, fieldSchema.LookupFields[j]) != undefined)
|
|
1648
|
-
result += GetObjectByString(fldLookupData_1, fieldSchema.LookupFields[j]).toString() + ' ';
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
updateObj[searchAlias_1] = result === null || result === void 0 ? void 0 : result.trim();
|
|
1652
|
-
//** Ends here */
|
|
1653
|
-
}
|
|
1654
|
-
resolve();
|
|
1655
|
-
});
|
|
1656
1632
|
}
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1633
|
+
updateObj[searchAlias] = result === null || result === void 0 ? void 0 : result.trim();
|
|
1634
|
+
//** Ends here */
|
|
1635
|
+
}
|
|
1636
|
+
// resolve()
|
|
1637
|
+
// });
|
|
1638
|
+
return [3 /*break*/, 20];
|
|
1639
|
+
case 6:
|
|
1640
|
+
if (!fieldSchema.LookupObject) return [3 /*break*/, 8];
|
|
1641
|
+
aggregateArry.push({ $match: { _id: fldValue } });
|
|
1642
|
+
aggregateArry.push({ $project: project });
|
|
1643
|
+
return [4 /*yield*/, db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray()];
|
|
1644
|
+
case 7:
|
|
1645
|
+
// db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
|
|
1646
|
+
data = _d.sent();
|
|
1647
|
+
// if (err) {
|
|
1648
|
+
// errorHandler(fldValue, err);
|
|
1649
|
+
// } else
|
|
1650
|
+
if (data && data.length > 0) {
|
|
1651
|
+
fldLookupData = data[0];
|
|
1652
|
+
updateObj[alias] = fldLookupData;
|
|
1653
|
+
result = '';
|
|
1654
|
+
if (fieldSchema.LookupFields != undefined) {
|
|
1655
|
+
for (j = 0; j < fieldSchema.LookupFields.length; j++) {
|
|
1656
|
+
if (GetObjectByString(fldLookupData, fieldSchema.LookupFields[j]) != undefined)
|
|
1657
|
+
result += GetObjectByString(fldLookupData, fieldSchema.LookupFields[j]).toString() + ' ';
|
|
1663
1658
|
}
|
|
1664
|
-
aggregateArry.push({ $unwind: { path: '$Data' } });
|
|
1665
|
-
aggregateArry.push({ $project: { _id: 0, Key: '$Data.Key', Value: '$Data.Value', IsActive: '$Data.IsActive' } });
|
|
1666
|
-
aggregateArry.push({ $match: { 'Key': fldValue_1 } });
|
|
1667
|
-
db.collection('ListSchema').aggregate(aggregateArry).toArray(function (err, data) {
|
|
1668
|
-
var _a;
|
|
1669
|
-
if (err) {
|
|
1670
|
-
errorHandler(fldValue_1, err);
|
|
1671
|
-
}
|
|
1672
|
-
else if (data && data.length > 0) {
|
|
1673
|
-
fldLookupData_1 = data[0];
|
|
1674
|
-
updateObj[alias_1] = fldLookupData_1;
|
|
1675
|
-
//** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
|
|
1676
|
-
updateObj[searchAlias_1] = (_a = fldLookupData_1.Value) === null || _a === void 0 ? void 0 : _a.trim();
|
|
1677
|
-
//** Ends here */
|
|
1678
|
-
}
|
|
1679
|
-
resolve();
|
|
1680
|
-
});
|
|
1681
1659
|
}
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
}
|
|
1736
|
-
break;
|
|
1737
|
-
case "file":
|
|
1738
|
-
case "image":
|
|
1739
|
-
if (!fieldSchema.IsMultiple) {
|
|
1740
|
-
aggregateArry.push({ $match: { '_id': fldValue_1 } });
|
|
1741
|
-
project['FileName'] = 1;
|
|
1742
|
-
aggregateArry.push({ $project: project });
|
|
1743
|
-
db.collection('Drive').aggregate(aggregateArry).toArray(function (err, data) {
|
|
1744
|
-
if (err) {
|
|
1745
|
-
errorHandler(fldValue_1, err);
|
|
1746
|
-
}
|
|
1747
|
-
else if (data && data.length > 0) {
|
|
1748
|
-
fldLookupData_1 = data[0];
|
|
1749
|
-
updateObj[alias_1] = fldLookupData_1;
|
|
1660
|
+
updateObj[searchAlias] = result === null || result === void 0 ? void 0 : result.trim();
|
|
1661
|
+
//** Ends here */
|
|
1662
|
+
}
|
|
1663
|
+
return [3 /*break*/, 10];
|
|
1664
|
+
case 8:
|
|
1665
|
+
if (fieldSchema.IsMultipleListSchemaName) {
|
|
1666
|
+
aggregateArry.push({ $match: { 'Name': { $in: fieldSchema.ListSchemaName } } });
|
|
1667
|
+
}
|
|
1668
|
+
else {
|
|
1669
|
+
aggregateArry.push({ $match: { 'Name': fieldSchema.ListSchemaName } });
|
|
1670
|
+
}
|
|
1671
|
+
aggregateArry.push({ $unwind: { path: '$Data' } });
|
|
1672
|
+
aggregateArry.push({ $project: { _id: 0, Key: '$Data.Key', Value: '$Data.Value', IsActive: '$Data.IsActive' } });
|
|
1673
|
+
aggregateArry.push({ $match: { 'Key': fldValue } });
|
|
1674
|
+
return [4 /*yield*/, db.collection('ListSchema').aggregate(aggregateArry).toArray()];
|
|
1675
|
+
case 9:
|
|
1676
|
+
// db.collection('ListSchema').aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
|
|
1677
|
+
data = _d.sent();
|
|
1678
|
+
// if (err) {
|
|
1679
|
+
// errorHandler(fldValue, err);
|
|
1680
|
+
// }
|
|
1681
|
+
// else
|
|
1682
|
+
if (data && data.length > 0) {
|
|
1683
|
+
fldLookupData = data[0];
|
|
1684
|
+
updateObj[alias] = fldLookupData;
|
|
1685
|
+
//** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
|
|
1686
|
+
updateObj[searchAlias] = (_a = fldLookupData.Value) === null || _a === void 0 ? void 0 : _a.trim();
|
|
1687
|
+
//** Ends here */
|
|
1688
|
+
}
|
|
1689
|
+
_d.label = 10;
|
|
1690
|
+
case 10: return [3 /*break*/, 20];
|
|
1691
|
+
case 11:
|
|
1692
|
+
if (!fieldSchema.LookupObject) return [3 /*break*/, 13];
|
|
1693
|
+
aggregateArry.push({ $match: { '_id': { $in: fldValue } } });
|
|
1694
|
+
aggregateArry.push({ $project: project });
|
|
1695
|
+
return [4 /*yield*/, db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray()];
|
|
1696
|
+
case 12:
|
|
1697
|
+
// db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
|
|
1698
|
+
data = _d.sent();
|
|
1699
|
+
// if (err) {
|
|
1700
|
+
// errorHandler(fldValue, err);
|
|
1701
|
+
// }
|
|
1702
|
+
// else
|
|
1703
|
+
if (data && data.length > 0) {
|
|
1704
|
+
fldLookupData = data;
|
|
1705
|
+
updateObj[alias] = fldLookupData;
|
|
1706
|
+
result = '';
|
|
1707
|
+
for (i = 0; i < data.length; i++) {
|
|
1708
|
+
lookupRecord = data[i];
|
|
1709
|
+
if (fieldSchema.LookupFields != undefined) {
|
|
1710
|
+
for (j = 0; j < fieldSchema.LookupFields.length; j++) {
|
|
1711
|
+
if (GetObjectByString(lookupRecord, fieldSchema.LookupFields[j]) != undefined)
|
|
1712
|
+
result += GetObjectByString(lookupRecord, fieldSchema.LookupFields[j]).toString() + ' ';
|
|
1750
1713
|
}
|
|
1751
|
-
|
|
1752
|
-
});
|
|
1714
|
+
}
|
|
1753
1715
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1716
|
+
updateObj[searchAlias] = result === null || result === void 0 ? void 0 : result.trim();
|
|
1717
|
+
//** Ends here */
|
|
1718
|
+
}
|
|
1719
|
+
return [3 /*break*/, 15];
|
|
1720
|
+
case 13:
|
|
1721
|
+
aggregateArry.push({ $match: { 'Name': fieldSchema.ListSchemaName } });
|
|
1722
|
+
aggregateArry.push({ $unwind: { path: '$Data' } });
|
|
1723
|
+
aggregateArry.push({ $project: { _id: 0, Key: '$Data.Key', Value: '$Data.Value', IsActive: '$Data.IsActive' } });
|
|
1724
|
+
aggregateArry.push({ $match: { 'Key': { $in: fldValue } } });
|
|
1725
|
+
return [4 /*yield*/, db.collection('ListSchema').aggregate(aggregateArry).toArray()];
|
|
1726
|
+
case 14:
|
|
1727
|
+
// db.collection('ListSchema').aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
|
|
1728
|
+
data = _d.sent();
|
|
1729
|
+
// if (err) {
|
|
1730
|
+
// errorHandler(fldValue, err);
|
|
1731
|
+
// }
|
|
1732
|
+
// else
|
|
1733
|
+
if (data && data.length > 0) {
|
|
1734
|
+
fldLookupData = data;
|
|
1735
|
+
updateObj[alias] = fldLookupData;
|
|
1736
|
+
result = '';
|
|
1737
|
+
for (i = 0; i < data.length; i++) {
|
|
1738
|
+
lookupRecord = data[i];
|
|
1739
|
+
result += ((_b = lookupRecord.Value) === null || _b === void 0 ? void 0 : _b.toString()) + ' ';
|
|
1756
1740
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1741
|
+
updateObj[searchAlias] = result === null || result === void 0 ? void 0 : result.trim();
|
|
1742
|
+
//** Ends here */
|
|
1743
|
+
}
|
|
1744
|
+
_d.label = 15;
|
|
1745
|
+
case 15: return [3 /*break*/, 20];
|
|
1746
|
+
case 16:
|
|
1747
|
+
if (!!fieldSchema.IsMultiple) return [3 /*break*/, 18];
|
|
1748
|
+
aggregateArry.push({ $match: { '_id': fldValue } });
|
|
1749
|
+
project['FileName'] = 1;
|
|
1750
|
+
aggregateArry.push({ $project: project });
|
|
1751
|
+
return [4 /*yield*/, db.collection('Drive').aggregate(aggregateArry).toArray()];
|
|
1752
|
+
case 17:
|
|
1753
|
+
// db.collection('Drive').aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
|
|
1754
|
+
data = _d.sent();
|
|
1755
|
+
// if (err) {
|
|
1756
|
+
// errorHandler(fldValue, err);
|
|
1757
|
+
// }
|
|
1758
|
+
// else
|
|
1759
|
+
if (data && data.length > 0) {
|
|
1760
|
+
fldLookupData = data[0];
|
|
1761
|
+
updateObj[alias] = fldLookupData;
|
|
1762
|
+
}
|
|
1763
|
+
_d.label = 18;
|
|
1764
|
+
case 18:
|
|
1765
|
+
// else {
|
|
1766
|
+
// resolve();
|
|
1767
|
+
// }
|
|
1768
|
+
return [3 /*break*/, 20];
|
|
1769
|
+
case 19:
|
|
1770
|
+
// resolve()
|
|
1771
|
+
return [3 /*break*/, 20];
|
|
1772
|
+
case 20: return [3 /*break*/, 22];
|
|
1773
|
+
case 21:
|
|
1774
|
+
updateObj[alias] = fldLookupData;
|
|
1775
|
+
// Below if cond was added by Shahzaib on 05/09/2022
|
|
1776
|
+
if (['dropdown', 'lookup', 'multilookup', 'multiselect'].includes(fieldSchema.UIDataType)) {
|
|
1777
|
+
updateObj[searchAlias] = "";
|
|
1778
|
+
}
|
|
1779
|
+
_d.label = 22;
|
|
1780
|
+
case 22: return [3 /*break*/, 24];
|
|
1781
|
+
case 23:
|
|
1782
|
+
error_2 = _d.sent();
|
|
1783
|
+
fieldValueType = (Array.isArray(fldValue) ? 'array' : '');
|
|
1784
|
+
if (!fieldValueType) {
|
|
1785
|
+
fieldValueType = typeof (fldValue);
|
|
1786
|
+
}
|
|
1787
|
+
errMsg = "Error Info: Error in Function BuildLookupDataField in Common Module for Company - " + (db.databaseName) + ", ObjectName - " + (fieldSchema.LookupObject || '') + ", FieldName - " + (fieldSchema.Name || '') + " for value - " + fldValue + " and data type of values is " + (fieldValueType || '') + " ";
|
|
1788
|
+
console.error(errMsg, '\n', error_2);
|
|
1789
|
+
return [3 /*break*/, 24];
|
|
1790
|
+
case 24: return [2 /*return*/];
|
|
1770
1791
|
}
|
|
1771
|
-
}
|
|
1772
|
-
else {
|
|
1773
|
-
resolve();
|
|
1774
|
-
}
|
|
1792
|
+
});
|
|
1775
1793
|
});
|
|
1776
1794
|
}
|
|
1777
1795
|
exports.BuildLookupDataField = BuildLookupDataField;
|
|
@@ -3683,7 +3701,7 @@ function UpdateTagCountAfterDelete(objectids, objectName, db, params) {
|
|
|
3683
3701
|
}
|
|
3684
3702
|
if (params && params.isBuiltOnPromise === true) {
|
|
3685
3703
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
3686
|
-
var records, tags, i, field,
|
|
3704
|
+
var records, tags, i, field, error_3;
|
|
3687
3705
|
return __generator(this, function (_a) {
|
|
3688
3706
|
switch (_a.label) {
|
|
3689
3707
|
case 0:
|
|
@@ -3703,8 +3721,8 @@ function UpdateTagCountAfterDelete(objectids, objectName, db, params) {
|
|
|
3703
3721
|
resolve();
|
|
3704
3722
|
return [3 /*break*/, 4];
|
|
3705
3723
|
case 3:
|
|
3706
|
-
|
|
3707
|
-
reject(
|
|
3724
|
+
error_3 = _a.sent();
|
|
3725
|
+
reject(error_3);
|
|
3708
3726
|
return [3 /*break*/, 4];
|
|
3709
3727
|
case 4: return [2 /*return*/];
|
|
3710
3728
|
}
|
|
@@ -4243,7 +4261,7 @@ exports.GetDayIndex = GetDayIndex;
|
|
|
4243
4261
|
function GetUserProfile(msp_d, db, mdb, next) {
|
|
4244
4262
|
var _a;
|
|
4245
4263
|
return __awaiter(this, void 0, void 0, function () {
|
|
4246
|
-
var userData, userProfile_1,
|
|
4264
|
+
var userData, userProfile_1, error_4, objectIDs_1, modules_1, licenceDetail, companylicenceDetail, receptionLicense, moduleList, _loop_17, i, error_5;
|
|
4247
4265
|
return __generator(this, function (_b) {
|
|
4248
4266
|
switch (_b.label) {
|
|
4249
4267
|
case 0:
|
|
@@ -4280,7 +4298,7 @@ function GetUserProfile(msp_d, db, mdb, next) {
|
|
|
4280
4298
|
userProfile_1 = _b.sent();
|
|
4281
4299
|
return [3 /*break*/, 5];
|
|
4282
4300
|
case 4:
|
|
4283
|
-
|
|
4301
|
+
error_4 = _b.sent();
|
|
4284
4302
|
console.log('No Module provided to userprofile');
|
|
4285
4303
|
return [2 /*return*/, { statusCode: 500, message: "Your profile doesn't have any module access. Please contact your Administrator.", data: {} }];
|
|
4286
4304
|
case 5:
|
|
@@ -4345,9 +4363,9 @@ function GetUserProfile(msp_d, db, mdb, next) {
|
|
|
4345
4363
|
case 10: return [2 /*return*/, { statusCode: 200, message: "There is no licence assigned to this user, please contact your administrator.", data: {} }];
|
|
4346
4364
|
case 11: return [3 /*break*/, 13];
|
|
4347
4365
|
case 12:
|
|
4348
|
-
|
|
4349
|
-
console.error("Internal Error in GetUserProfile Utility function : " +
|
|
4350
|
-
next(
|
|
4366
|
+
error_5 = _b.sent();
|
|
4367
|
+
console.error("Internal Error in GetUserProfile Utility function : " + error_5);
|
|
4368
|
+
next(error_5);
|
|
4351
4369
|
return [3 /*break*/, 13];
|
|
4352
4370
|
case 13: return [2 /*return*/];
|
|
4353
4371
|
}
|
|
@@ -4425,7 +4443,7 @@ exports.RemoveFieldsFromFilters = RemoveFieldsFromFilters;
|
|
|
4425
4443
|
*/
|
|
4426
4444
|
function ErrorHandlerForServices(Error, ServiceOrigin, EmailConfig, Module, db) {
|
|
4427
4445
|
return __awaiter(this, void 0, void 0, function () {
|
|
4428
|
-
var _a, mailObj, errorObj, sendMailResult, ErrorOrigin, ErrorData,
|
|
4446
|
+
var _a, mailObj, errorObj, sendMailResult, ErrorOrigin, ErrorData, error_6;
|
|
4429
4447
|
return __generator(this, function (_b) {
|
|
4430
4448
|
switch (_b.label) {
|
|
4431
4449
|
case 0:
|
|
@@ -4448,8 +4466,8 @@ function ErrorHandlerForServices(Error, ServiceOrigin, EmailConfig, Module, db)
|
|
|
4448
4466
|
_b.label = 4;
|
|
4449
4467
|
case 4: return [3 /*break*/, 6];
|
|
4450
4468
|
case 5:
|
|
4451
|
-
|
|
4452
|
-
console.log("Error While connectin to Master DB",
|
|
4469
|
+
error_6 = _b.sent();
|
|
4470
|
+
console.log("Error While connectin to Master DB", error_6);
|
|
4453
4471
|
return [3 /*break*/, 6];
|
|
4454
4472
|
case 6: return [2 /*return*/];
|
|
4455
4473
|
}
|
|
@@ -5199,7 +5217,7 @@ exports.CheckExpressionOnDateField = CheckExpressionOnDateField;
|
|
|
5199
5217
|
*/
|
|
5200
5218
|
function CreateBanquetingVATSettingsData(msp_d, db, sdata, next) {
|
|
5201
5219
|
return __awaiter(this, void 0, void 0, function () {
|
|
5202
|
-
var userID, schemaData, _i, _a, field,
|
|
5220
|
+
var userID, schemaData, _i, _a, field, error_7;
|
|
5203
5221
|
return __generator(this, function (_b) {
|
|
5204
5222
|
switch (_b.label) {
|
|
5205
5223
|
case 0:
|
|
@@ -5226,8 +5244,8 @@ function CreateBanquetingVATSettingsData(msp_d, db, sdata, next) {
|
|
|
5226
5244
|
return [3 /*break*/, 2];
|
|
5227
5245
|
case 5: return [3 /*break*/, 7];
|
|
5228
5246
|
case 6:
|
|
5229
|
-
|
|
5230
|
-
next(
|
|
5247
|
+
error_7 = _b.sent();
|
|
5248
|
+
next(error_7);
|
|
5231
5249
|
return [3 /*break*/, 7];
|
|
5232
5250
|
case 7: return [2 /*return*/];
|
|
5233
5251
|
}
|