tango-app-api-audit 3.4.20 → 3.4.21
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/package.json +1 -1
- package/src/controllers/audit.controllers.js +29 -8
- package/src/controllers/traxAudit.controllers.js +324 -399
- package/src/docs/traxAudit.docs.js +2 -2
- package/src/dtos/traxAudit.dtos.js +3 -3
- package/src/routes/traxAudit.routes.js +2 -2
- package/src/validation/traxAuditValidation.js +5 -2
package/package.json
CHANGED
|
@@ -874,18 +874,10 @@ export async function workSpace( req, res ) {
|
|
|
874
874
|
},
|
|
875
875
|
},
|
|
876
876
|
},
|
|
877
|
-
// {
|
|
878
|
-
// $group: {
|
|
879
|
-
// _id: { clientId: '$clientId', storeId: '$storeId' },
|
|
880
|
-
// clientId: { $first: '$clientId' },
|
|
881
|
-
// completedStoresCount: { $sum: '$completed' },
|
|
882
|
-
// },
|
|
883
|
-
// },
|
|
884
877
|
{
|
|
885
878
|
$group: {
|
|
886
879
|
_id: '$clientId',
|
|
887
880
|
clientId: { $first: '$clientId' },
|
|
888
|
-
// completedStoresCount: { $first: '$completedStoresCount' },
|
|
889
881
|
completedStoresCount: { $sum: '$completed' },
|
|
890
882
|
},
|
|
891
883
|
},
|
|
@@ -979,6 +971,31 @@ export async function workSpace( req, res ) {
|
|
|
979
971
|
},
|
|
980
972
|
];
|
|
981
973
|
|
|
974
|
+
// const userDrafted = [
|
|
975
|
+
// {
|
|
976
|
+
// $match: {
|
|
977
|
+
// $and: [
|
|
978
|
+
// { clientId: { $in: clientList } },
|
|
979
|
+
// { userId: { $eq: req.user._id } },
|
|
980
|
+
// { auditStatus: { $eq: true } },
|
|
981
|
+
// { moduleType: { $eq: inputData.moduleType } },
|
|
982
|
+
// { createdAt: { $gte: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ) } },
|
|
983
|
+
// { createdAt: { $lte: dateRange.end } },
|
|
984
|
+
// ],
|
|
985
|
+
// },
|
|
986
|
+
// },
|
|
987
|
+
// {
|
|
988
|
+
// $limit: 1,
|
|
989
|
+
// },
|
|
990
|
+
// {
|
|
991
|
+
// $project: {
|
|
992
|
+
// clienId: 1,
|
|
993
|
+
// auditStatus: 1,
|
|
994
|
+
// },
|
|
995
|
+
// },
|
|
996
|
+
|
|
997
|
+
// ];
|
|
998
|
+
|
|
982
999
|
const userAsignAudit = [
|
|
983
1000
|
{
|
|
984
1001
|
$match: {
|
|
@@ -1035,6 +1052,9 @@ export async function workSpace( req, res ) {
|
|
|
1035
1052
|
const userIncompleteFilesCount = await aggregateUserAudit(
|
|
1036
1053
|
userIncompleteFiles,
|
|
1037
1054
|
);
|
|
1055
|
+
// const userDraftedCount = await aggregateUserAudit(
|
|
1056
|
+
// userDrafted,
|
|
1057
|
+
// );
|
|
1038
1058
|
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
1039
1059
|
const completedStoresCount = await aggregateStoreAudit( completedStores );
|
|
1040
1060
|
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
@@ -1082,6 +1102,7 @@ export async function workSpace( req, res ) {
|
|
|
1082
1102
|
queueName: merge[i].queueName,
|
|
1083
1103
|
isDraft: merge[i]?.isDrafted || false,
|
|
1084
1104
|
isEnable:
|
|
1105
|
+
// userDraftedCount.length > 0 && !merge[i].isDrafted? 0:
|
|
1085
1106
|
Number( pending ) > 0 ||
|
|
1086
1107
|
merge[i].isDrafted ||
|
|
1087
1108
|
( merge[i].userAsignedCount && merge[i].userAsignedCount > 0 ) ||
|
|
@@ -451,7 +451,7 @@ export async function workSpace( req, res ) {
|
|
|
451
451
|
}
|
|
452
452
|
} catch ( error ) {
|
|
453
453
|
const err = error.message || 'Internal Server Error';
|
|
454
|
-
logger.
|
|
454
|
+
logger.error( { error: error, message: req.query, function: 'workSpace' } );
|
|
455
455
|
return res.sendError( err, 500 );
|
|
456
456
|
}
|
|
457
457
|
}
|
|
@@ -1469,7 +1469,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1469
1469
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1470
1470
|
} catch ( error ) {
|
|
1471
1471
|
const err = error.message || 'Internal Server Error';
|
|
1472
|
-
logger.
|
|
1472
|
+
logger.error( { error: error, message: req.body, function: 'userAuditHistory' } );
|
|
1473
1473
|
return res.sendError( err, 500 );
|
|
1474
1474
|
}
|
|
1475
1475
|
}
|
|
@@ -1498,241 +1498,240 @@ export async function clientMetrics( req, res ) {
|
|
|
1498
1498
|
{ clientId: { $in: inputData.filterByClient } },
|
|
1499
1499
|
);
|
|
1500
1500
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1501
|
+
let query = [];
|
|
1502
|
+
if ( [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType ) ) {
|
|
1503
|
+
query =[
|
|
1504
|
+
{
|
|
1505
|
+
$match: {
|
|
1506
|
+
$and: filter,
|
|
1507
|
+
},
|
|
1505
1508
|
},
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1509
|
+
{
|
|
1510
|
+
$group: {
|
|
1511
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate', moduleType: '$moduleType' },
|
|
1512
|
+
fileDate: { $last: '$fileDate' },
|
|
1513
|
+
clientId: { $last: '$clientId' },
|
|
1514
|
+
clientName: { $last: '$clientName' },
|
|
1515
|
+
moduleType: { $last: '$moduleType' },
|
|
1516
|
+
installedStore: { $last: '$installedStore' },
|
|
1517
|
+
queueName: { $last: '$queueName' },
|
|
1518
|
+
totalFilesCount: { $sum: 1 },
|
|
1519
|
+
},
|
|
1517
1520
|
},
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1521
|
+
{
|
|
1522
|
+
$project: {
|
|
1523
|
+
fileDate: 1,
|
|
1524
|
+
clientId: 1,
|
|
1525
|
+
clientName: 1,
|
|
1526
|
+
queueName: 1,
|
|
1527
|
+
installedStore: 1,
|
|
1528
|
+
totalFilesCount: 1,
|
|
1529
|
+
moduleType: 1,
|
|
1530
|
+
notAssignedCount: { $ifNull: [ 0, 0 ] },
|
|
1531
|
+
clientStatus: { $ifNull: [ '', '' ] },
|
|
1532
|
+
},
|
|
1530
1533
|
},
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
'pipeline': [
|
|
1534
|
+
{
|
|
1535
|
+
$lookup: {
|
|
1536
|
+
'from': 'storeEmpDetection',
|
|
1537
|
+
'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalFilesCount' },
|
|
1538
|
+
'pipeline': [
|
|
1537
1539
|
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1540
|
+
{
|
|
1541
|
+
$match: {
|
|
1542
|
+
$expr: {
|
|
1543
|
+
$and: storeAuditFilter,
|
|
1544
|
+
},
|
|
1542
1545
|
},
|
|
1543
1546
|
},
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1547
|
+
{
|
|
1548
|
+
$project: {
|
|
1549
|
+
completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
|
|
1550
|
+
notAssignedStores: { $cond: [ { $eq: [ '$status', 'not_assign' ] }, 1, 0 ] },
|
|
1551
|
+
inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
|
|
1552
|
+
},
|
|
1550
1553
|
},
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1554
|
+
{
|
|
1555
|
+
$group: {
|
|
1556
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate' },
|
|
1557
|
+
completedStores: { $sum: '$completedStores' },
|
|
1558
|
+
inprogressStores: { $sum: '$inprogressStores' },
|
|
1559
|
+
notAssignedStores: { $sum: '$notAssignedStores' },
|
|
1560
|
+
fileCount: { $sum: 1 },
|
|
1561
|
+
},
|
|
1559
1562
|
},
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
],
|
|
1578
|
-
}, 1 ],
|
|
1563
|
+
{
|
|
1564
|
+
$project: {
|
|
1565
|
+
_id: 0,
|
|
1566
|
+
completedStores: 1,
|
|
1567
|
+
inprogressStores: 1,
|
|
1568
|
+
notAssignedStores: 1,
|
|
1569
|
+
fileCount: { $ifNull: [ '$fileCount', 0 ] },
|
|
1570
|
+
completionPercentage: { $ifNull: [
|
|
1571
|
+
{
|
|
1572
|
+
$round: [ {
|
|
1573
|
+
$multiply: [
|
|
1574
|
+
100, {
|
|
1575
|
+
$divide: [
|
|
1576
|
+
'$completedStores', '$$totalAuditFiles',
|
|
1577
|
+
],
|
|
1578
|
+
},
|
|
1579
|
+
],
|
|
1580
|
+
}, 1 ],
|
|
1579
1581
|
|
|
1582
|
+
},
|
|
1583
|
+
0,
|
|
1584
|
+
],
|
|
1580
1585
|
},
|
|
1581
|
-
0,
|
|
1582
|
-
],
|
|
1583
1586
|
},
|
|
1584
1587
|
},
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
},
|
|
1588
|
-
},
|
|
1589
|
-
{
|
|
1590
|
-
$unwind: {
|
|
1591
|
-
path: '$binaryAudit',
|
|
1592
|
-
preserveNullAndEmptyArrays: true,
|
|
1588
|
+
], 'as': 'binaryAudit',
|
|
1589
|
+
},
|
|
1593
1590
|
},
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
fileDate: 1,
|
|
1599
|
-
clientId: 1,
|
|
1600
|
-
clientName: 1,
|
|
1601
|
-
totalFilesCount: 1,
|
|
1602
|
-
moduleType: 1,
|
|
1603
|
-
value: {
|
|
1604
|
-
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
1591
|
+
{
|
|
1592
|
+
$unwind: {
|
|
1593
|
+
path: '$binaryAudit',
|
|
1594
|
+
preserveNullAndEmptyArrays: true,
|
|
1605
1595
|
},
|
|
1606
|
-
installedStore: 1,
|
|
1607
|
-
// notAssignedStores: '$binaryAudit.notAssignedStores',
|
|
1608
|
-
inprogressStoresCount: '$binaryAudit.inprogressStores',
|
|
1609
|
-
// fileCount: '$binaryAudit.fileCount',
|
|
1610
|
-
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
|
|
1611
|
-
clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
|
|
1612
|
-
completedStores: '$binaryAudit.completedStores',
|
|
1613
|
-
completionPercentage: '$binaryAudit.completionPercentage',
|
|
1614
|
-
|
|
1615
1596
|
},
|
|
1616
|
-
|
|
1617
|
-
|
|
1597
|
+
{
|
|
1598
|
+
$project: {
|
|
1599
|
+
_id: 0,
|
|
1600
|
+
fileDate: 1,
|
|
1601
|
+
clientId: 1,
|
|
1602
|
+
clientName: 1,
|
|
1603
|
+
totalFilesCount: 1,
|
|
1604
|
+
moduleType: 1,
|
|
1605
|
+
value: {
|
|
1606
|
+
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
1607
|
+
},
|
|
1608
|
+
installedStore: 1,
|
|
1609
|
+
inprogressStoresCount: '$binaryAudit.inprogressStores',
|
|
1610
|
+
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
|
|
1611
|
+
clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
|
|
1612
|
+
completedStores: '$binaryAudit.completedStores',
|
|
1613
|
+
completionPercentage: '$binaryAudit.completionPercentage',
|
|
1618
1614
|
|
|
1619
|
-
|
|
1620
|
-
{
|
|
1621
|
-
$match: {
|
|
1622
|
-
$and: filter,
|
|
1615
|
+
},
|
|
1623
1616
|
},
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
moduleType: { $last: '$moduleType' },
|
|
1632
|
-
installedStore: { $last: '$installedStore' },
|
|
1633
|
-
queueName: { $last: '$queueName' },
|
|
1634
|
-
totalFilesCount: { $sum: 1 },
|
|
1617
|
+
];
|
|
1618
|
+
} else {
|
|
1619
|
+
query = [
|
|
1620
|
+
{
|
|
1621
|
+
$match: {
|
|
1622
|
+
$and: filter,
|
|
1623
|
+
},
|
|
1635
1624
|
},
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
clientStatus: { $ifNull: [ '', '' ] },
|
|
1625
|
+
{
|
|
1626
|
+
$group: {
|
|
1627
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate', moduleType: '$moduleType' },
|
|
1628
|
+
fileDate: { $last: '$fileDate' },
|
|
1629
|
+
clientId: { $last: '$clientId' },
|
|
1630
|
+
clientName: { $last: '$clientName' },
|
|
1631
|
+
moduleType: { $last: '$moduleType' },
|
|
1632
|
+
installedStore: { $last: '$installedStore' },
|
|
1633
|
+
queueName: { $last: '$queueName' },
|
|
1634
|
+
totalFilesCount: { $sum: 1 },
|
|
1635
|
+
},
|
|
1648
1636
|
},
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1637
|
+
{
|
|
1638
|
+
$project: {
|
|
1639
|
+
fileDate: 1,
|
|
1640
|
+
clientId: 1,
|
|
1641
|
+
clientName: 1,
|
|
1642
|
+
queueName: 1,
|
|
1643
|
+
installedStore: 1,
|
|
1644
|
+
totalFilesCount: 1,
|
|
1645
|
+
moduleType: 1,
|
|
1646
|
+
notAssignedCount: { $ifNull: [ 0, 0 ] },
|
|
1647
|
+
clientStatus: { $ifNull: [ '', '' ] },
|
|
1648
|
+
},
|
|
1649
|
+
},
|
|
1650
|
+
{
|
|
1651
|
+
$lookup: {
|
|
1652
|
+
'from': 'binaryAudit',
|
|
1653
|
+
'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalFilesCount' },
|
|
1654
|
+
'pipeline': [
|
|
1655
1655
|
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1656
|
+
{
|
|
1657
|
+
$match: {
|
|
1658
|
+
$expr: {
|
|
1659
|
+
$and: storeAuditFilter,
|
|
1660
|
+
},
|
|
1660
1661
|
},
|
|
1661
1662
|
},
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1663
|
+
{
|
|
1664
|
+
$project: {
|
|
1665
|
+
completedStores: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
|
|
1666
|
+
notAssignedStores: { $cond: [ { $eq: [ '$auditStatus', 'not_assign' ] }, 1, 0 ] },
|
|
1667
|
+
inprogressStores: { $cond: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
|
|
1668
|
+
},
|
|
1668
1669
|
},
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1670
|
+
{
|
|
1671
|
+
$group: {
|
|
1672
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate' },
|
|
1673
|
+
completedStores: { $sum: '$completedStores' },
|
|
1674
|
+
inprogressStores: { $sum: '$inprogressStores' },
|
|
1675
|
+
notAssignedStores: { $sum: '$notAssignedStores' },
|
|
1676
|
+
fileCount: { $sum: 1 },
|
|
1677
|
+
},
|
|
1677
1678
|
},
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
],
|
|
1696
|
-
}, 1 ],
|
|
1679
|
+
{
|
|
1680
|
+
$project: {
|
|
1681
|
+
_id: 0,
|
|
1682
|
+
completedStores: 1,
|
|
1683
|
+
inprogressStores: 1,
|
|
1684
|
+
notAssignedStores: 1,
|
|
1685
|
+
fileCount: { $ifNull: [ '$fileCount', 0 ] },
|
|
1686
|
+
completionPercentage: { $ifNull: [
|
|
1687
|
+
{
|
|
1688
|
+
$round: [ {
|
|
1689
|
+
$multiply: [
|
|
1690
|
+
100, {
|
|
1691
|
+
$divide: [
|
|
1692
|
+
'$completedStores', '$$totalAuditFiles',
|
|
1693
|
+
],
|
|
1694
|
+
},
|
|
1695
|
+
],
|
|
1696
|
+
}, 1 ],
|
|
1697
1697
|
|
|
1698
|
+
},
|
|
1699
|
+
0,
|
|
1700
|
+
],
|
|
1698
1701
|
},
|
|
1699
|
-
0,
|
|
1700
|
-
],
|
|
1701
1702
|
},
|
|
1702
1703
|
},
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
},
|
|
1706
|
-
},
|
|
1707
|
-
{
|
|
1708
|
-
$unwind: {
|
|
1709
|
-
path: '$binaryAudit',
|
|
1710
|
-
preserveNullAndEmptyArrays: true,
|
|
1704
|
+
], 'as': 'binaryAudit',
|
|
1705
|
+
},
|
|
1711
1706
|
},
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
fileDate: 1,
|
|
1717
|
-
clientId: 1,
|
|
1718
|
-
clientName: 1,
|
|
1719
|
-
totalFilesCount: 1,
|
|
1720
|
-
moduleType: 1,
|
|
1721
|
-
value: {
|
|
1722
|
-
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
1707
|
+
{
|
|
1708
|
+
$unwind: {
|
|
1709
|
+
path: '$binaryAudit',
|
|
1710
|
+
preserveNullAndEmptyArrays: true,
|
|
1723
1711
|
},
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1712
|
+
},
|
|
1713
|
+
{
|
|
1714
|
+
$project: {
|
|
1715
|
+
_id: 0,
|
|
1716
|
+
fileDate: 1,
|
|
1717
|
+
clientId: 1,
|
|
1718
|
+
clientName: 1,
|
|
1719
|
+
totalFilesCount: 1,
|
|
1720
|
+
moduleType: 1,
|
|
1721
|
+
value: {
|
|
1722
|
+
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
1723
|
+
},
|
|
1724
|
+
installedStore: 1,
|
|
1725
|
+
inprogressStoresCount: '$binaryAudit.inprogressStores',
|
|
1726
|
+
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
|
|
1727
|
+
clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
|
|
1728
|
+
completedStores: '$binaryAudit.completedStores',
|
|
1729
|
+
completionPercentage: '$binaryAudit.completionPercentage',
|
|
1732
1730
|
|
|
1731
|
+
},
|
|
1733
1732
|
},
|
|
1734
|
-
|
|
1735
|
-
|
|
1733
|
+
];
|
|
1734
|
+
}
|
|
1736
1735
|
|
|
1737
1736
|
|
|
1738
1737
|
if ( inputData?.filterByStatus?.length> 0 ) {
|
|
@@ -1742,12 +1741,6 @@ export async function clientMetrics( req, res ) {
|
|
|
1742
1741
|
},
|
|
1743
1742
|
|
|
1744
1743
|
);
|
|
1745
|
-
MappingQuery.push(
|
|
1746
|
-
{
|
|
1747
|
-
$match: { clientStatus: { $in: inputData.filterByStatus } },
|
|
1748
|
-
},
|
|
1749
|
-
|
|
1750
|
-
);
|
|
1751
1744
|
}
|
|
1752
1745
|
|
|
1753
1746
|
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
@@ -1762,18 +1755,6 @@ export async function clientMetrics( req, res ) {
|
|
|
1762
1755
|
|
|
1763
1756
|
},
|
|
1764
1757
|
} );
|
|
1765
|
-
|
|
1766
|
-
MappingQuery.push( {
|
|
1767
|
-
$match: {
|
|
1768
|
-
$or: [
|
|
1769
|
-
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1770
|
-
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1771
|
-
{ moduleType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1772
|
-
{ clientStatus: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1773
|
-
],
|
|
1774
|
-
|
|
1775
|
-
},
|
|
1776
|
-
} );
|
|
1777
1758
|
}
|
|
1778
1759
|
if ( inputData.sortColumnName ) {
|
|
1779
1760
|
const sortBy = inputData.sortBy || -1;
|
|
@@ -1782,23 +1763,15 @@ export async function clientMetrics( req, res ) {
|
|
|
1782
1763
|
$sort: { [sortColumn]: sortBy },
|
|
1783
1764
|
},
|
|
1784
1765
|
);
|
|
1785
|
-
|
|
1786
|
-
MappingQuery.push( {
|
|
1787
|
-
$sort: { [sortColumn]: sortBy },
|
|
1788
|
-
},
|
|
1789
|
-
);
|
|
1790
1766
|
}
|
|
1791
1767
|
|
|
1792
|
-
const count =
|
|
1793
|
-
logger.info( { count: count } );
|
|
1768
|
+
const count = await aggregateTraxAuditData( query );
|
|
1794
1769
|
if ( count.length == 0 ) {
|
|
1795
1770
|
return res.sendError( 'No Data Found', 204 );
|
|
1796
1771
|
}
|
|
1797
1772
|
|
|
1798
1773
|
if ( inputData.isExport ) {
|
|
1799
1774
|
query.push( { $limit: 10000 } );
|
|
1800
|
-
|
|
1801
|
-
MappingQuery.push( { $limit: 10000 } );
|
|
1802
1775
|
} else {
|
|
1803
1776
|
query.push( {
|
|
1804
1777
|
$skip: offset,
|
|
@@ -1806,13 +1779,6 @@ export async function clientMetrics( req, res ) {
|
|
|
1806
1779
|
{
|
|
1807
1780
|
$limit: limit,
|
|
1808
1781
|
} );
|
|
1809
|
-
|
|
1810
|
-
MappingQuery.push( {
|
|
1811
|
-
$skip: offset,
|
|
1812
|
-
},
|
|
1813
|
-
{
|
|
1814
|
-
$limit: limit,
|
|
1815
|
-
} );
|
|
1816
1782
|
}
|
|
1817
1783
|
if ( inputData.isExport ) {
|
|
1818
1784
|
query.push(
|
|
@@ -1823,32 +1789,10 @@ export async function clientMetrics( req, res ) {
|
|
|
1823
1789
|
'Brand Name': '$clientName',
|
|
1824
1790
|
'Brand Id': '$clientId',
|
|
1825
1791
|
'Product Type': '$value',
|
|
1826
|
-
// 'Completed Percentage': '$completionPercentage',
|
|
1827
|
-
'Installed Stores': '$installedStore',
|
|
1828
|
-
'Audit Stores': '$totalFilesCount',
|
|
1829
|
-
'Inprogress Stores': '$inprogressStoresCount',
|
|
1830
|
-
'Not Assigned Stores': '$notAssignedCount',
|
|
1831
|
-
// 'Not Assigned Stores': '$notAssignedStores',
|
|
1832
|
-
'Completed Stores': '$completedStores',
|
|
1833
|
-
'Status': '$clientStatus',
|
|
1834
|
-
},
|
|
1835
|
-
},
|
|
1836
|
-
);
|
|
1837
|
-
|
|
1838
|
-
MappingQuery.push(
|
|
1839
|
-
{
|
|
1840
|
-
$project: {
|
|
1841
|
-
'_id': 0,
|
|
1842
|
-
'File Date': '$fileDate',
|
|
1843
|
-
'Brand Name': '$clientName',
|
|
1844
|
-
'Brand Id': '$clientId',
|
|
1845
|
-
'Product Type': '$value',
|
|
1846
|
-
// 'Completed Percentage': '$completionPercentage',
|
|
1847
1792
|
'Installed Stores': '$installedStore',
|
|
1848
1793
|
'Audit Stores': '$totalFilesCount',
|
|
1849
1794
|
'Inprogress Stores': '$inprogressStoresCount',
|
|
1850
1795
|
'Not Assigned Stores': '$notAssignedCount',
|
|
1851
|
-
// 'Not Assigned Stores': '$notAssignedStores',
|
|
1852
1796
|
'Completed Stores': '$completedStores',
|
|
1853
1797
|
'Status': '$clientStatus',
|
|
1854
1798
|
},
|
|
@@ -1856,7 +1800,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1856
1800
|
);
|
|
1857
1801
|
}
|
|
1858
1802
|
|
|
1859
|
-
const result =
|
|
1803
|
+
const result = await aggregateTraxAuditData( query );
|
|
1860
1804
|
if ( result.length == 0 ) {
|
|
1861
1805
|
return res.sendError( 'No Data Found', 204 );
|
|
1862
1806
|
}
|
|
@@ -1867,7 +1811,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1867
1811
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1868
1812
|
} catch ( error ) {
|
|
1869
1813
|
const err = error.error || 'Internal Server Error';
|
|
1870
|
-
logger.
|
|
1814
|
+
logger.error( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
1871
1815
|
return res.sendError( err, 500 );
|
|
1872
1816
|
}
|
|
1873
1817
|
}
|
|
@@ -1891,7 +1835,7 @@ export async function storeMetrics( req, res ) {
|
|
|
1891
1835
|
}
|
|
1892
1836
|
|
|
1893
1837
|
if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
|
|
1894
|
-
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
1838
|
+
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
1895
1839
|
}
|
|
1896
1840
|
|
|
1897
1841
|
if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
|
|
@@ -1940,6 +1884,7 @@ export async function storeMetrics( req, res ) {
|
|
|
1940
1884
|
fileDate: 1,
|
|
1941
1885
|
storeId: 1,
|
|
1942
1886
|
storeName: '$stores.storeName',
|
|
1887
|
+
zoneName: 1,
|
|
1943
1888
|
clientName: '',
|
|
1944
1889
|
clientId: 1,
|
|
1945
1890
|
moduleType: 1,
|
|
@@ -1955,7 +1900,6 @@ export async function storeMetrics( req, res ) {
|
|
|
1955
1900
|
userId: {
|
|
1956
1901
|
$arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], // need to check if no data
|
|
1957
1902
|
},
|
|
1958
|
-
// userId: 1,
|
|
1959
1903
|
auditType: 1,
|
|
1960
1904
|
beforeCount: 1,
|
|
1961
1905
|
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
@@ -2031,6 +1975,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2031
1975
|
fileDate: 1,
|
|
2032
1976
|
storeId: 1,
|
|
2033
1977
|
storeName: 1,
|
|
1978
|
+
zoneName: 1,
|
|
2034
1979
|
userName: '$users.userName',
|
|
2035
1980
|
userEmail: '$users.userEmail',
|
|
2036
1981
|
clientId: 1,
|
|
@@ -2137,9 +2082,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2137
2082
|
questionType: 1,
|
|
2138
2083
|
userComments: 1,
|
|
2139
2084
|
answer: 1,
|
|
2140
|
-
// userId: {
|
|
2141
|
-
// $arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], //need to check if no data
|
|
2142
|
-
// },
|
|
2143
2085
|
userId: 1,
|
|
2144
2086
|
auditType: 1,
|
|
2145
2087
|
beforeCount: 1,
|
|
@@ -2277,6 +2219,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2277
2219
|
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2278
2220
|
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2279
2221
|
{ storeName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2222
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2280
2223
|
{ userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2281
2224
|
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2282
2225
|
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
@@ -2324,7 +2267,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2324
2267
|
},
|
|
2325
2268
|
);
|
|
2326
2269
|
}
|
|
2327
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2270
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2328
2271
|
|
|
2329
2272
|
|
|
2330
2273
|
if ( count.length == 0 ) {
|
|
@@ -2348,7 +2291,10 @@ export async function storeMetrics( req, res ) {
|
|
|
2348
2291
|
$limit: limit,
|
|
2349
2292
|
} );
|
|
2350
2293
|
}
|
|
2351
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2294
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2295
|
+
if ( result.length == 0 ) {
|
|
2296
|
+
return res.sendError( 'No data Found', 204 );
|
|
2297
|
+
}
|
|
2352
2298
|
if ( inputData.isExport ) {
|
|
2353
2299
|
const exportdata = [];
|
|
2354
2300
|
result.forEach( ( element ) => {
|
|
@@ -2389,11 +2335,13 @@ export async function storeMetrics( req, res ) {
|
|
|
2389
2335
|
temp['Accuracy'] = element.accuracy;
|
|
2390
2336
|
break;
|
|
2391
2337
|
case 'uniform-detection':
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2338
|
+
temp['Before Count'] = element.beforeCount;
|
|
2339
|
+
temp['After Count'] = element.afterCount;
|
|
2340
|
+
temp['Status'] = toCamelCase( element.status );
|
|
2341
|
+
temp['Accuracy'] = element.accuracy;
|
|
2342
|
+
break;
|
|
2343
|
+
case 'hygiene':
|
|
2344
|
+
temp['Zone Name'] = element.zoneName;
|
|
2397
2345
|
temp['Before Count'] = element.beforeCount;
|
|
2398
2346
|
temp['After Count'] = element.afterCount;
|
|
2399
2347
|
temp['Status'] = toCamelCase( element.status );
|
|
@@ -2509,11 +2457,6 @@ export async function userMetrics( req, res ) {
|
|
|
2509
2457
|
beforeCount: 1,
|
|
2510
2458
|
afterCount: 1,
|
|
2511
2459
|
createdAt: 1,
|
|
2512
|
-
// mappingPerc: { $round: [
|
|
2513
|
-
// { $multiply: [
|
|
2514
|
-
// { $divide: [ '$afterCount', '$beforeCount' ] }, 100,
|
|
2515
|
-
// ] }, 2,
|
|
2516
|
-
// ] },
|
|
2517
2460
|
checkIntime: 1,
|
|
2518
2461
|
checkOutTime: 1,
|
|
2519
2462
|
differenceInSeconds: {
|
|
@@ -2532,7 +2475,6 @@ export async function userMetrics( req, res ) {
|
|
|
2532
2475
|
checkOutTime: 1,
|
|
2533
2476
|
moduleType: 1,
|
|
2534
2477
|
value: 1,
|
|
2535
|
-
// mappingPerc: 1,
|
|
2536
2478
|
hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
|
|
2537
2479
|
minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
|
|
2538
2480
|
seconds: { $mod: [ '$differenceInSeconds', 60 ] },
|
|
@@ -2552,7 +2494,6 @@ export async function userMetrics( req, res ) {
|
|
|
2552
2494
|
moduleType: 1,
|
|
2553
2495
|
value: 1,
|
|
2554
2496
|
createdAt: 1,
|
|
2555
|
-
// mappingPerc: 1,
|
|
2556
2497
|
hours: {
|
|
2557
2498
|
$cond: {
|
|
2558
2499
|
if: { $lt: [ '$hours', 10 ] },
|
|
@@ -2591,7 +2532,6 @@ export async function userMetrics( req, res ) {
|
|
|
2591
2532
|
value: {
|
|
2592
2533
|
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' },
|
|
2593
2534
|
},
|
|
2594
|
-
// mappingPerc: 1,
|
|
2595
2535
|
workingHours: {
|
|
2596
2536
|
$concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
|
|
2597
2537
|
},
|
|
@@ -2636,7 +2576,6 @@ export async function userMetrics( req, res ) {
|
|
|
2636
2576
|
value: {
|
|
2637
2577
|
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' },
|
|
2638
2578
|
},
|
|
2639
|
-
// mappingPerc: 1,
|
|
2640
2579
|
checkIntime: {
|
|
2641
2580
|
$dateToString: {
|
|
2642
2581
|
format: '%Y-%m-%d %H:%M:%S',
|
|
@@ -2676,7 +2615,7 @@ export async function userMetrics( req, res ) {
|
|
|
2676
2615
|
);
|
|
2677
2616
|
}
|
|
2678
2617
|
|
|
2679
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2618
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2680
2619
|
if ( count.length == 0 ) {
|
|
2681
2620
|
return res.sendError( 'No Data Found', 204 );
|
|
2682
2621
|
}
|
|
@@ -2698,8 +2637,8 @@ export async function userMetrics( req, res ) {
|
|
|
2698
2637
|
'Check OutTime': '$checkOutTime',
|
|
2699
2638
|
'Working Hours': '$workingHours',
|
|
2700
2639
|
'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
|
|
2701
|
-
// 'Mapping Percentage': '$mappingPerc',
|
|
2702
2640
|
};
|
|
2641
|
+
|
|
2703
2642
|
const YesNo = {
|
|
2704
2643
|
'_id': 0,
|
|
2705
2644
|
'User Name': '$userName',
|
|
@@ -2710,9 +2649,8 @@ export async function userMetrics( req, res ) {
|
|
|
2710
2649
|
'Check OutTime': '$checkOutTime',
|
|
2711
2650
|
'Working Hours': '$workingHours',
|
|
2712
2651
|
'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
|
|
2713
|
-
// 'Mapping Percentage': '$mappingPerc',
|
|
2714
2652
|
};
|
|
2715
|
-
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?
|
|
2653
|
+
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?
|
|
2716
2654
|
query.push(
|
|
2717
2655
|
{
|
|
2718
2656
|
$project: detection,
|
|
@@ -2726,7 +2664,10 @@ export async function userMetrics( req, res ) {
|
|
|
2726
2664
|
}
|
|
2727
2665
|
|
|
2728
2666
|
|
|
2729
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2667
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2668
|
+
if ( result.length == 0 ) {
|
|
2669
|
+
return res.sendError( 'No Data Found', 204 );
|
|
2670
|
+
}
|
|
2730
2671
|
if ( inputData.isExport ) {
|
|
2731
2672
|
await download( result, res );
|
|
2732
2673
|
return;
|
|
@@ -2734,7 +2675,7 @@ export async function userMetrics( req, res ) {
|
|
|
2734
2675
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
2735
2676
|
} catch ( error ) {
|
|
2736
2677
|
const err = error.error || 'Internal Server Error';
|
|
2737
|
-
logger.
|
|
2678
|
+
logger.error( { error: error, message: req.body, function: 'userMetrics' } );
|
|
2738
2679
|
return res.sendError( err, 500 );
|
|
2739
2680
|
}
|
|
2740
2681
|
}
|
|
@@ -2851,6 +2792,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2851
2792
|
$match: {
|
|
2852
2793
|
$or: [
|
|
2853
2794
|
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2795
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2854
2796
|
{ fileDate: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2855
2797
|
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2856
2798
|
{ auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
|
|
@@ -2870,7 +2812,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2870
2812
|
},
|
|
2871
2813
|
);
|
|
2872
2814
|
}
|
|
2873
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2815
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2874
2816
|
if ( count.length == 0 ) {
|
|
2875
2817
|
return res.sendError( 'No Data Found', 204 );
|
|
2876
2818
|
}
|
|
@@ -2886,7 +2828,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2886
2828
|
} );
|
|
2887
2829
|
}
|
|
2888
2830
|
|
|
2889
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2831
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2890
2832
|
if ( inputData.isExport ) {
|
|
2891
2833
|
const exportdata = [];
|
|
2892
2834
|
result.forEach( ( element ) => {
|
|
@@ -2915,8 +2857,10 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2915
2857
|
temp['Before Count'] = element.beforeCount;
|
|
2916
2858
|
break;
|
|
2917
2859
|
case 'uniform-detection':
|
|
2918
|
-
|
|
2919
|
-
|
|
2860
|
+
temp['Before Count'] = element.beforeCount;
|
|
2861
|
+
break;
|
|
2862
|
+
case 'hygiene':
|
|
2863
|
+
temp['Zone Name'] = element.zoneName;
|
|
2920
2864
|
temp['Before Count'] = element.beforeCount;
|
|
2921
2865
|
break;
|
|
2922
2866
|
}
|
|
@@ -3082,7 +3026,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
3082
3026
|
},
|
|
3083
3027
|
];
|
|
3084
3028
|
|
|
3085
|
-
const storeAudit = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3029
|
+
const storeAudit = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3086
3030
|
if ( storeAudit.length > 0 ) {
|
|
3087
3031
|
temp.inprogressStores= storeAudit[0].inprogressStores;
|
|
3088
3032
|
temp.completedStores = storeAudit[0].completedStores;
|
|
@@ -3270,7 +3214,7 @@ export async function summarySplit( req, res ) {
|
|
|
3270
3214
|
},
|
|
3271
3215
|
},
|
|
3272
3216
|
];
|
|
3273
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3217
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3274
3218
|
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3275
3219
|
result[0].totalCount = totalCount[0]?.total;
|
|
3276
3220
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
@@ -3300,7 +3244,7 @@ export async function overviewTable( req, res ) {
|
|
|
3300
3244
|
}
|
|
3301
3245
|
|
|
3302
3246
|
if ( inputData.filterByStatus.length > 0 ) {
|
|
3303
|
-
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3247
|
+
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3304
3248
|
}
|
|
3305
3249
|
|
|
3306
3250
|
const query =[
|
|
@@ -3315,6 +3259,7 @@ export async function overviewTable( req, res ) {
|
|
|
3315
3259
|
_id: 0,
|
|
3316
3260
|
storeId: 1,
|
|
3317
3261
|
clientId: 1,
|
|
3262
|
+
zoneName: 1,
|
|
3318
3263
|
streamName: 1,
|
|
3319
3264
|
tempId: 1,
|
|
3320
3265
|
question: 1,
|
|
@@ -3332,41 +3277,14 @@ export async function overviewTable( req, res ) {
|
|
|
3332
3277
|
auditType: 1,
|
|
3333
3278
|
status: 1,
|
|
3334
3279
|
auditStatus: 1,
|
|
3335
|
-
// userId: 1,
|
|
3336
3280
|
},
|
|
3337
3281
|
},
|
|
3338
|
-
// {
|
|
3339
|
-
// $lookup: {
|
|
3340
|
-
// from: 'users',
|
|
3341
|
-
// let: { userId: '$userId' },
|
|
3342
|
-
// pipeline: [
|
|
3343
|
-
// {
|
|
3344
|
-
// $match: {
|
|
3345
|
-
// $expr: {
|
|
3346
|
-
// $eq: [ '$_id', '$$userId' ],
|
|
3347
|
-
// },
|
|
3348
|
-
// },
|
|
3349
|
-
// },
|
|
3350
|
-
// {
|
|
3351
|
-
// $project: {
|
|
3352
|
-
// userName: 1,
|
|
3353
|
-
// userEmail: '$email',
|
|
3354
|
-
// },
|
|
3355
|
-
// },
|
|
3356
|
-
// ], as: 'user',
|
|
3357
|
-
// },
|
|
3358
|
-
// },
|
|
3359
|
-
// {
|
|
3360
|
-
// $unwind: {
|
|
3361
|
-
// path: '$user',
|
|
3362
|
-
// preserveNullAndEmptyArrays: true,
|
|
3363
|
-
// },
|
|
3364
|
-
// },
|
|
3365
3282
|
{
|
|
3366
3283
|
$project: {
|
|
3367
3284
|
storeId: 1,
|
|
3368
3285
|
clientId: 1,
|
|
3369
3286
|
streamName: 1,
|
|
3287
|
+
zoneName: 1,
|
|
3370
3288
|
tempId: 1,
|
|
3371
3289
|
question: 1,
|
|
3372
3290
|
questionType: 1,
|
|
@@ -3380,8 +3298,6 @@ export async function overviewTable( req, res ) {
|
|
|
3380
3298
|
auditType: 1,
|
|
3381
3299
|
status: 1,
|
|
3382
3300
|
auditStatus: 1,
|
|
3383
|
-
// userName: '$user.userName',
|
|
3384
|
-
// userEmail: '$user.userEmail',
|
|
3385
3301
|
|
|
3386
3302
|
},
|
|
3387
3303
|
},
|
|
@@ -3392,6 +3308,7 @@ export async function overviewTable( req, res ) {
|
|
|
3392
3308
|
$or: [
|
|
3393
3309
|
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3394
3310
|
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3311
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3395
3312
|
{ fileDate: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3396
3313
|
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3397
3314
|
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
@@ -3402,8 +3319,6 @@ export async function overviewTable( req, res ) {
|
|
|
3402
3319
|
{ question: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3403
3320
|
{ answer: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3404
3321
|
{ userComments: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3405
|
-
// { userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3406
|
-
// { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3407
3322
|
],
|
|
3408
3323
|
|
|
3409
3324
|
},
|
|
@@ -3417,7 +3332,7 @@ export async function overviewTable( req, res ) {
|
|
|
3417
3332
|
},
|
|
3418
3333
|
);
|
|
3419
3334
|
}
|
|
3420
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3335
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3421
3336
|
if ( count.length == 0 ) {
|
|
3422
3337
|
return res.sendError( 'No Data Found', 204 );
|
|
3423
3338
|
}
|
|
@@ -3432,7 +3347,7 @@ export async function overviewTable( req, res ) {
|
|
|
3432
3347
|
$limit: limit,
|
|
3433
3348
|
} );
|
|
3434
3349
|
}
|
|
3435
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3350
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3436
3351
|
if ( inputData.isExport ) {
|
|
3437
3352
|
const exportdata = [];
|
|
3438
3353
|
result.forEach( ( element ) => {
|
|
@@ -3469,11 +3384,13 @@ export async function overviewTable( req, res ) {
|
|
|
3469
3384
|
temp['Status'] = toCamelCase( element.status );
|
|
3470
3385
|
break;
|
|
3471
3386
|
case 'uniform-detection':
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3387
|
+
temp['Before Count'] = element.beforeCount;
|
|
3388
|
+
temp['After Count'] = element.afterCount;
|
|
3389
|
+
temp['Audit Type'] = element.auditType;
|
|
3390
|
+
temp['Status'] = toCamelCase( element.status );
|
|
3391
|
+
break;
|
|
3392
|
+
case 'hygiene':
|
|
3393
|
+
temp['Zone Name'] = element.zoneName;
|
|
3477
3394
|
temp['Before Count'] = element.beforeCount;
|
|
3478
3395
|
temp['After Count'] = element.afterCount;
|
|
3479
3396
|
temp['Audit Type'] = element.auditType;
|
|
@@ -4103,82 +4020,90 @@ export async function reTrigger( req, res ) {
|
|
|
4103
4020
|
const message = req.sqs;
|
|
4104
4021
|
const sqs = JSON.parse( process.env.SQS );
|
|
4105
4022
|
const getQueueName = await findOneClient( { clientId: req.audit.clientId }, { 'auditConfigs': 1 } );
|
|
4106
|
-
const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : getQueueName?.auditConfigs?.traxQueueName?.mobileDetection;
|
|
4023
|
+
const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : inputData.moduleType == 'mobile-detection' ?getQueueName?.auditConfigs?.traxQueueName?.mobileDetection : getQueueName?.auditConfigs?.traxQueueName?.hygiene;
|
|
4107
4024
|
if ( !getQueueName || queueName == '' ) {
|
|
4108
4025
|
return res.sendError( 'queueName does not create', 400 );
|
|
4109
4026
|
}
|
|
4110
|
-
|
|
4111
|
-
fileDate: message.fileDate,
|
|
4112
|
-
moduleType: message.moduleType, auditStatus: 'completed' } );
|
|
4113
|
-
const msg = {
|
|
4027
|
+
let getQuery ={
|
|
4114
4028
|
storeId: message.storeId,
|
|
4115
4029
|
fileDate: message.fileDate,
|
|
4116
|
-
moduleType: message.moduleType,
|
|
4117
|
-
inputBucketName: message.inputBucketName,
|
|
4118
|
-
questionType: message.questionType,
|
|
4119
|
-
question: message.question,
|
|
4120
|
-
folderPath: message.folderPath,
|
|
4121
|
-
fileCount: message.fileCount,
|
|
4122
|
-
auditType: getRecord > 0? 'ReAudit':'Audit',
|
|
4030
|
+
moduleType: message.moduleType, auditStatus: 'completed',
|
|
4123
4031
|
};
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4032
|
+
inputData.moduleType == 'hygiene'? getQuery.zoneName = inputData?.zoneName : null;
|
|
4033
|
+
const getRecord = await countDocumentsUserEmpDetection( getQuery );
|
|
4034
|
+
const msg = {
|
|
4035
|
+
storeId: message.storeId,
|
|
4036
|
+
zoneName: message.zoneName,
|
|
4037
|
+
fileDate: message.fileDate,
|
|
4038
|
+
moduleType: message.moduleType,
|
|
4039
|
+
inputBucketName: message.inputBucketName,
|
|
4040
|
+
questionType: message.questionType,
|
|
4041
|
+
question: message.question,
|
|
4042
|
+
folderPath: message.folderPath,
|
|
4043
|
+
fileCount: message.fileCount,
|
|
4044
|
+
auditType: getRecord > 0? 'ReAudit':'Audit',
|
|
4045
|
+
};
|
|
4046
|
+
const sqsProduceQueue = {
|
|
4047
|
+
QueueUrl: `${sqs.url}${queueName}`,
|
|
4048
|
+
MessageBody: JSON.stringify( msg ),
|
|
4049
|
+
};
|
|
4050
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
4051
|
+
if ( sqsQueue?.errorCode ) {
|
|
4052
|
+
const error = sqsQueue?.errorMsg;
|
|
4053
|
+
const code = sqsQueue?.errorCode;
|
|
4054
|
+
return res.sendError( error, code );
|
|
4055
|
+
} else {
|
|
4056
|
+
if ( req.audit.status !== 'completed' ) {
|
|
4057
|
+
const userRecord = {
|
|
4058
|
+
auditStatus: 'skipped',
|
|
4059
|
+
isDraft: false,
|
|
4060
|
+
};
|
|
4061
|
+
const query = {
|
|
4062
|
+
storeId: inputData.storeId,
|
|
4063
|
+
fileDate: inputData.fileDate,
|
|
4064
|
+
auditStatus: req.audit.status,
|
|
4065
|
+
moduleType: inputData.moduleType,
|
|
4066
|
+
|
|
4067
|
+
};
|
|
4068
|
+
inputData.moduleType == 'hygiene'? query.zoneName = inputData?.zoneName : null;
|
|
4069
|
+
await updateOneUserEmpDetection( query, userRecord );
|
|
4070
|
+
}
|
|
4071
|
+
|
|
4072
|
+
const storeQuery = {
|
|
4140
4073
|
storeId: inputData.storeId,
|
|
4141
4074
|
fileDate: inputData.fileDate,
|
|
4142
|
-
auditStatus: req.audit.status,
|
|
4143
4075
|
moduleType: inputData.moduleType,
|
|
4144
4076
|
|
|
4145
4077
|
};
|
|
4146
|
-
|
|
4147
|
-
}
|
|
4148
|
-
|
|
4149
|
-
const storeQuery = {
|
|
4150
|
-
storeId: inputData.storeId,
|
|
4151
|
-
fileDate: inputData.fileDate,
|
|
4152
|
-
moduleType: inputData.moduleType,
|
|
4078
|
+
inputData.moduleType == 'hygiene'? storeQuery.zoneName = inputData?.zoneName : null;
|
|
4153
4079
|
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
status: 'not_assign',
|
|
4158
|
-
};
|
|
4080
|
+
const storeRecord = {
|
|
4081
|
+
status: 'not_assign',
|
|
4082
|
+
};
|
|
4159
4083
|
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4084
|
+
await updateOneStoreEmpDetection( storeQuery, storeRecord );
|
|
4085
|
+
const logData = {
|
|
4086
|
+
userId: req.user._id,
|
|
4087
|
+
userName: req.user.userName,
|
|
4088
|
+
logType: 'traxAudit',
|
|
4089
|
+
logSubType: 'reTrigger',
|
|
4090
|
+
logData: {
|
|
4091
|
+
beforeCount: message.fileCount,
|
|
4092
|
+
afterCount: '',
|
|
4093
|
+
fileDate: inputData.fileDate,
|
|
4094
|
+
auditType: req.audit.auditType,
|
|
4095
|
+
storeId: inputData.storeId,
|
|
4096
|
+
zoneName: inputData.zoneName,
|
|
4097
|
+
moduleType: inputData.moduleType,
|
|
4098
|
+
queueName: queueName,
|
|
4099
|
+
triggerBy: req.user.userName,
|
|
4100
|
+
triggerId: req.user._id,
|
|
4101
|
+
},
|
|
4102
|
+
createdAt: new Date(),
|
|
4103
|
+
};
|
|
4104
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
4105
|
+
}
|
|
4106
|
+
return res.sendSuccess( { result: 'The File has been Re-Triggered Succesfully' } );
|
|
4182
4107
|
} catch ( error ) {
|
|
4183
4108
|
const err = error.message;
|
|
4184
4109
|
logger.error( { error: error, message: req.body, function: 'reTrigger' } );
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema,
|
|
2
|
+
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema, reTriggerSchema } from '../dtos/traxAudit.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const traxAuditDocs = {
|
|
5
5
|
|
|
@@ -418,7 +418,7 @@ export const traxAuditDocs = {
|
|
|
418
418
|
requestBody: {
|
|
419
419
|
content: {
|
|
420
420
|
'application/json': {
|
|
421
|
-
schema: j2s(
|
|
421
|
+
schema: j2s( reTriggerSchema ).swagger,
|
|
422
422
|
},
|
|
423
423
|
},
|
|
424
424
|
},
|
|
@@ -284,13 +284,13 @@ export const saveValid = {
|
|
|
284
284
|
};
|
|
285
285
|
|
|
286
286
|
|
|
287
|
-
export const
|
|
287
|
+
export const reTriggerSchema = joi.object( {
|
|
288
288
|
fileDate: joi.string().required(),
|
|
289
289
|
storeId: joi.string().required(),
|
|
290
290
|
moduleType: joi.string().required(),
|
|
291
|
-
|
|
291
|
+
zoneName: joi.string().optional(),
|
|
292
292
|
} );
|
|
293
293
|
|
|
294
294
|
export const reTriggerValid = {
|
|
295
|
-
body:
|
|
295
|
+
body: reTriggerSchema,
|
|
296
296
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
3
|
-
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid,
|
|
3
|
+
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid, reTriggerValid } from '../dtos/traxAudit.dtos.js';
|
|
4
4
|
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
5
5
|
import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save, reTrigger } from '../controllers/traxAudit.controllers.js';
|
|
6
6
|
import { isMappingAuditInputFolderExist, isTraxAuditDocumentExist, isuserEmpDocumentExist, validateBinaryAudit, validateUserEmpDetection } from '../validation/traxAuditValidation.js';
|
|
@@ -30,7 +30,7 @@ traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler,
|
|
|
30
30
|
traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( overAllAuditSummaryValid ), overAllAuditSummary );
|
|
31
31
|
traxAuditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler,
|
|
32
32
|
accessVerification( { userType: [ 'tango' ], access: [ { featureName: 'TangoAdmin', name: 'TicketConfiguration', permissions: [ 'isEdit' ] } ] } ),
|
|
33
|
-
validate(
|
|
33
|
+
validate( reTriggerValid ), isuserEmpDocumentExist, isMappingAuditInputFolderExist, reTrigger );
|
|
34
34
|
|
|
35
35
|
// summary
|
|
36
36
|
|
|
@@ -122,11 +122,15 @@ export async function isTraxAuditDocumentExist( req, res, next ) {
|
|
|
122
122
|
export async function isuserEmpDocumentExist( req, res, next ) {
|
|
123
123
|
try {
|
|
124
124
|
const inputData = req.body;
|
|
125
|
-
|
|
125
|
+
if ( inputData.moduleType == 'hygiene' && inputData?.zoneName == undefined ) {
|
|
126
|
+
return res.sendError( 'ZoneName is required', 400 );
|
|
127
|
+
}
|
|
128
|
+
let query={
|
|
126
129
|
storeId: inputData.storeId,
|
|
127
130
|
fileDate: inputData.fileDate,
|
|
128
131
|
moduleType: inputData.moduleType,
|
|
129
132
|
};
|
|
133
|
+
inputData.moduleType == 'hygiene'? query.zoneName = inputData?.zoneName : null;
|
|
130
134
|
const auditInfo = await findOneStoreEmpDetection( query );
|
|
131
135
|
if ( auditInfo ) {
|
|
132
136
|
const sqs = await findOneTraxAuditData( query, { sqs: 1 } );
|
|
@@ -146,7 +150,6 @@ export async function isuserEmpDocumentExist( req, res, next ) {
|
|
|
146
150
|
|
|
147
151
|
export async function isMappingAuditInputFolderExist( req, res, next ) {
|
|
148
152
|
try {
|
|
149
|
-
// const inputData = req.method === 'POST' ? req.body : req.query;
|
|
150
153
|
const params={
|
|
151
154
|
Bucket: req.sqs.inputBucketName,
|
|
152
155
|
Key: req.sqs.folderPath.replace( /\/$/, '' ),
|