tango-app-api-audit 3.4.20 → 3.4.22
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 +65 -8
- package/src/controllers/traxAudit.controllers.js +347 -419
- 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
|
@@ -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;
|
|
@@ -3123,7 +3067,30 @@ export async function summarySplit( req, res ) {
|
|
|
3123
3067
|
{ moduleType: { $eq: inputData.moduleType } },
|
|
3124
3068
|
{ clientId: { $in: inputData.clientId } },
|
|
3125
3069
|
];
|
|
3070
|
+
const totalQuery = [
|
|
3071
|
+
{
|
|
3072
|
+
$match: {
|
|
3073
|
+
$and: filters,
|
|
3074
|
+
},
|
|
3126
3075
|
|
|
3076
|
+
},
|
|
3077
|
+
{
|
|
3078
|
+
$group: {
|
|
3079
|
+
_id: null,
|
|
3080
|
+
total: { $sum: 1 },
|
|
3081
|
+
},
|
|
3082
|
+
},
|
|
3083
|
+
{
|
|
3084
|
+
$project: {
|
|
3085
|
+
_id: 0,
|
|
3086
|
+
total: 1,
|
|
3087
|
+
},
|
|
3088
|
+
},
|
|
3089
|
+
];
|
|
3090
|
+
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3091
|
+
if ( totalCount.length == 0 ) {
|
|
3092
|
+
return res.sendError( 'No Data Found', 204 );
|
|
3093
|
+
}
|
|
3127
3094
|
|
|
3128
3095
|
const binaryAuditQuery =[
|
|
3129
3096
|
{
|
|
@@ -3250,28 +3217,8 @@ export async function summarySplit( req, res ) {
|
|
|
3250
3217
|
},
|
|
3251
3218
|
},
|
|
3252
3219
|
];
|
|
3253
|
-
const totalQuery = [
|
|
3254
|
-
{
|
|
3255
|
-
$match: {
|
|
3256
|
-
$and: filters,
|
|
3257
|
-
},
|
|
3258
3220
|
|
|
3259
|
-
|
|
3260
|
-
{
|
|
3261
|
-
$group: {
|
|
3262
|
-
_id: null,
|
|
3263
|
-
total: { $sum: 1 },
|
|
3264
|
-
},
|
|
3265
|
-
},
|
|
3266
|
-
{
|
|
3267
|
-
$project: {
|
|
3268
|
-
_id: 0,
|
|
3269
|
-
total: 1,
|
|
3270
|
-
},
|
|
3271
|
-
},
|
|
3272
|
-
];
|
|
3273
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3274
|
-
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3221
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3275
3222
|
result[0].totalCount = totalCount[0]?.total;
|
|
3276
3223
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
3277
3224
|
} catch ( error ) {
|
|
@@ -3300,7 +3247,7 @@ export async function overviewTable( req, res ) {
|
|
|
3300
3247
|
}
|
|
3301
3248
|
|
|
3302
3249
|
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 } } );
|
|
3250
|
+
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3304
3251
|
}
|
|
3305
3252
|
|
|
3306
3253
|
const query =[
|
|
@@ -3315,6 +3262,7 @@ export async function overviewTable( req, res ) {
|
|
|
3315
3262
|
_id: 0,
|
|
3316
3263
|
storeId: 1,
|
|
3317
3264
|
clientId: 1,
|
|
3265
|
+
zoneName: 1,
|
|
3318
3266
|
streamName: 1,
|
|
3319
3267
|
tempId: 1,
|
|
3320
3268
|
question: 1,
|
|
@@ -3332,41 +3280,14 @@ export async function overviewTable( req, res ) {
|
|
|
3332
3280
|
auditType: 1,
|
|
3333
3281
|
status: 1,
|
|
3334
3282
|
auditStatus: 1,
|
|
3335
|
-
// userId: 1,
|
|
3336
3283
|
},
|
|
3337
3284
|
},
|
|
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
3285
|
{
|
|
3366
3286
|
$project: {
|
|
3367
3287
|
storeId: 1,
|
|
3368
3288
|
clientId: 1,
|
|
3369
3289
|
streamName: 1,
|
|
3290
|
+
zoneName: 1,
|
|
3370
3291
|
tempId: 1,
|
|
3371
3292
|
question: 1,
|
|
3372
3293
|
questionType: 1,
|
|
@@ -3380,8 +3301,6 @@ export async function overviewTable( req, res ) {
|
|
|
3380
3301
|
auditType: 1,
|
|
3381
3302
|
status: 1,
|
|
3382
3303
|
auditStatus: 1,
|
|
3383
|
-
// userName: '$user.userName',
|
|
3384
|
-
// userEmail: '$user.userEmail',
|
|
3385
3304
|
|
|
3386
3305
|
},
|
|
3387
3306
|
},
|
|
@@ -3392,6 +3311,7 @@ export async function overviewTable( req, res ) {
|
|
|
3392
3311
|
$or: [
|
|
3393
3312
|
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3394
3313
|
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3314
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3395
3315
|
{ fileDate: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3396
3316
|
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3397
3317
|
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
@@ -3402,8 +3322,6 @@ export async function overviewTable( req, res ) {
|
|
|
3402
3322
|
{ question: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3403
3323
|
{ answer: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3404
3324
|
{ userComments: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3405
|
-
// { userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3406
|
-
// { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3407
3325
|
],
|
|
3408
3326
|
|
|
3409
3327
|
},
|
|
@@ -3417,7 +3335,7 @@ export async function overviewTable( req, res ) {
|
|
|
3417
3335
|
},
|
|
3418
3336
|
);
|
|
3419
3337
|
}
|
|
3420
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3338
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3421
3339
|
if ( count.length == 0 ) {
|
|
3422
3340
|
return res.sendError( 'No Data Found', 204 );
|
|
3423
3341
|
}
|
|
@@ -3432,7 +3350,7 @@ export async function overviewTable( req, res ) {
|
|
|
3432
3350
|
$limit: limit,
|
|
3433
3351
|
} );
|
|
3434
3352
|
}
|
|
3435
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3353
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3436
3354
|
if ( inputData.isExport ) {
|
|
3437
3355
|
const exportdata = [];
|
|
3438
3356
|
result.forEach( ( element ) => {
|
|
@@ -3469,11 +3387,13 @@ export async function overviewTable( req, res ) {
|
|
|
3469
3387
|
temp['Status'] = toCamelCase( element.status );
|
|
3470
3388
|
break;
|
|
3471
3389
|
case 'uniform-detection':
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3390
|
+
temp['Before Count'] = element.beforeCount;
|
|
3391
|
+
temp['After Count'] = element.afterCount;
|
|
3392
|
+
temp['Audit Type'] = element.auditType;
|
|
3393
|
+
temp['Status'] = toCamelCase( element.status );
|
|
3394
|
+
break;
|
|
3395
|
+
case 'hygiene':
|
|
3396
|
+
temp['Zone Name'] = element.zoneName;
|
|
3477
3397
|
temp['Before Count'] = element.beforeCount;
|
|
3478
3398
|
temp['After Count'] = element.afterCount;
|
|
3479
3399
|
temp['Audit Type'] = element.auditType;
|
|
@@ -4103,82 +4023,90 @@ export async function reTrigger( req, res ) {
|
|
|
4103
4023
|
const message = req.sqs;
|
|
4104
4024
|
const sqs = JSON.parse( process.env.SQS );
|
|
4105
4025
|
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;
|
|
4026
|
+
const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : inputData.moduleType == 'mobile-detection' ?getQueueName?.auditConfigs?.traxQueueName?.mobileDetection : getQueueName?.auditConfigs?.traxQueueName?.hygiene;
|
|
4107
4027
|
if ( !getQueueName || queueName == '' ) {
|
|
4108
4028
|
return res.sendError( 'queueName does not create', 400 );
|
|
4109
4029
|
}
|
|
4110
|
-
|
|
4111
|
-
fileDate: message.fileDate,
|
|
4112
|
-
moduleType: message.moduleType, auditStatus: 'completed' } );
|
|
4113
|
-
const msg = {
|
|
4030
|
+
let getQuery ={
|
|
4114
4031
|
storeId: message.storeId,
|
|
4115
4032
|
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',
|
|
4123
|
-
};
|
|
4124
|
-
const sqsProduceQueue = {
|
|
4125
|
-
QueueUrl: `${sqs.url}${queueName}`,
|
|
4126
|
-
MessageBody: JSON.stringify( msg ),
|
|
4033
|
+
moduleType: message.moduleType, auditStatus: 'completed',
|
|
4127
4034
|
};
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
const
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4035
|
+
inputData.moduleType == 'hygiene'? getQuery.zoneName = inputData?.zoneName : null;
|
|
4036
|
+
const getRecord = await countDocumentsUserEmpDetection( getQuery );
|
|
4037
|
+
const msg = {
|
|
4038
|
+
storeId: message.storeId,
|
|
4039
|
+
zoneName: message.zoneName,
|
|
4040
|
+
fileDate: message.fileDate,
|
|
4041
|
+
moduleType: message.moduleType,
|
|
4042
|
+
inputBucketName: message.inputBucketName,
|
|
4043
|
+
questionType: message.questionType,
|
|
4044
|
+
question: message.question,
|
|
4045
|
+
folderPath: message.folderPath,
|
|
4046
|
+
fileCount: message.fileCount,
|
|
4047
|
+
auditType: getRecord > 0? 'ReAudit':'Audit',
|
|
4048
|
+
};
|
|
4049
|
+
const sqsProduceQueue = {
|
|
4050
|
+
QueueUrl: `${sqs.url}${queueName}`,
|
|
4051
|
+
MessageBody: JSON.stringify( msg ),
|
|
4052
|
+
};
|
|
4053
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
4054
|
+
if ( sqsQueue?.errorCode ) {
|
|
4055
|
+
const error = sqsQueue?.errorMsg;
|
|
4056
|
+
const code = sqsQueue?.errorCode;
|
|
4057
|
+
return res.sendError( error, code );
|
|
4058
|
+
} else {
|
|
4059
|
+
if ( req.audit.status !== 'completed' ) {
|
|
4060
|
+
const userRecord = {
|
|
4061
|
+
auditStatus: 'skipped',
|
|
4062
|
+
isDraft: false,
|
|
4063
|
+
};
|
|
4064
|
+
const query = {
|
|
4065
|
+
storeId: inputData.storeId,
|
|
4066
|
+
fileDate: inputData.fileDate,
|
|
4067
|
+
auditStatus: req.audit.status,
|
|
4068
|
+
moduleType: inputData.moduleType,
|
|
4069
|
+
|
|
4070
|
+
};
|
|
4071
|
+
inputData.moduleType == 'hygiene'? query.zoneName = inputData?.zoneName : null;
|
|
4072
|
+
await updateOneUserEmpDetection( query, userRecord );
|
|
4073
|
+
}
|
|
4074
|
+
|
|
4075
|
+
const storeQuery = {
|
|
4140
4076
|
storeId: inputData.storeId,
|
|
4141
4077
|
fileDate: inputData.fileDate,
|
|
4142
|
-
auditStatus: req.audit.status,
|
|
4143
4078
|
moduleType: inputData.moduleType,
|
|
4144
4079
|
|
|
4145
4080
|
};
|
|
4146
|
-
|
|
4147
|
-
}
|
|
4081
|
+
inputData.moduleType == 'hygiene'? storeQuery.zoneName = inputData?.zoneName : null;
|
|
4148
4082
|
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
moduleType: inputData.moduleType,
|
|
4153
|
-
|
|
4154
|
-
};
|
|
4155
|
-
|
|
4156
|
-
const storeRecord = {
|
|
4157
|
-
status: 'not_assign',
|
|
4158
|
-
};
|
|
4083
|
+
const storeRecord = {
|
|
4084
|
+
status: 'not_assign',
|
|
4085
|
+
};
|
|
4159
4086
|
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4087
|
+
await updateOneStoreEmpDetection( storeQuery, storeRecord );
|
|
4088
|
+
const logData = {
|
|
4089
|
+
userId: req.user._id,
|
|
4090
|
+
userName: req.user.userName,
|
|
4091
|
+
logType: 'traxAudit',
|
|
4092
|
+
logSubType: 'reTrigger',
|
|
4093
|
+
logData: {
|
|
4094
|
+
beforeCount: message.fileCount,
|
|
4095
|
+
afterCount: '',
|
|
4096
|
+
fileDate: inputData.fileDate,
|
|
4097
|
+
auditType: req.audit.auditType,
|
|
4098
|
+
storeId: inputData.storeId,
|
|
4099
|
+
zoneName: inputData.zoneName,
|
|
4100
|
+
moduleType: inputData.moduleType,
|
|
4101
|
+
queueName: queueName,
|
|
4102
|
+
triggerBy: req.user.userName,
|
|
4103
|
+
triggerId: req.user._id,
|
|
4104
|
+
},
|
|
4105
|
+
createdAt: new Date(),
|
|
4106
|
+
};
|
|
4107
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
4108
|
+
}
|
|
4109
|
+
return res.sendSuccess( { result: 'The File has been Re-Triggered Succesfully' } );
|
|
4182
4110
|
} catch ( error ) {
|
|
4183
4111
|
const err = error.message;
|
|
4184
4112
|
logger.error( { error: error, message: req.body, function: 'reTrigger' } );
|