tango-app-api-audit 3.4.0-alpha.2 → 3.4.0-alpha.3
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
CHANGED
|
@@ -1159,6 +1159,7 @@ export async function saveBinary( req, res ) {
|
|
|
1159
1159
|
let update={
|
|
1160
1160
|
auditStatus: 'completed',
|
|
1161
1161
|
answer: inputData.answer,
|
|
1162
|
+
userCommands: inputData.userComments || '',
|
|
1162
1163
|
};
|
|
1163
1164
|
let updatDataunattended= await updateOneBinaryAuditModel( unattendedquery, update );
|
|
1164
1165
|
if ( updatDataunattended.modifiedCount==0 ) {
|
|
@@ -1480,3 +1481,815 @@ export async function userAuditHistory( req, res ) {
|
|
|
1480
1481
|
return res.sendError( err, 500 );
|
|
1481
1482
|
}
|
|
1482
1483
|
}
|
|
1484
|
+
|
|
1485
|
+
export async function clientMetrics( req, res ) {
|
|
1486
|
+
try {
|
|
1487
|
+
const inputData = req.body;
|
|
1488
|
+
const limit = inputData.limit || 10;
|
|
1489
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
1490
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
1491
|
+
let filter = [
|
|
1492
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
1493
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
1494
|
+
{ moduleType: { $eq: inputData.moduleType } },
|
|
1495
|
+
];
|
|
1496
|
+
|
|
1497
|
+
let storeAuditFilter = [
|
|
1498
|
+
{ $eq: [ '$clientId', '$$clientId' ] },
|
|
1499
|
+
{ $eq: [ '$fileDate', '$$fileDate' ] },
|
|
1500
|
+
{ $eq: [ '$moduleType', inputData.moduleType ] },
|
|
1501
|
+
|
|
1502
|
+
];
|
|
1503
|
+
|
|
1504
|
+
if ( inputData?.filterByClient?.length> 0 ) {
|
|
1505
|
+
filter.push(
|
|
1506
|
+
{ clientId: { $in: inputData.filterByClient } },
|
|
1507
|
+
);
|
|
1508
|
+
}
|
|
1509
|
+
const query = [
|
|
1510
|
+
{
|
|
1511
|
+
$match: {
|
|
1512
|
+
$and: filter,
|
|
1513
|
+
},
|
|
1514
|
+
},
|
|
1515
|
+
{
|
|
1516
|
+
$group: {
|
|
1517
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate', moduleType: '$moduleType' },
|
|
1518
|
+
fileDate: { $last: '$fileDate' },
|
|
1519
|
+
clientId: { $last: '$clientId' },
|
|
1520
|
+
clientName: { $last: '$clientName' },
|
|
1521
|
+
moduleType: { $last: '$moduleType' },
|
|
1522
|
+
installedStore: { $last: '$installedStore' },
|
|
1523
|
+
queueName: { $last: '$queueName' },
|
|
1524
|
+
totalFilesCount: { $sum: 1 },
|
|
1525
|
+
},
|
|
1526
|
+
},
|
|
1527
|
+
{
|
|
1528
|
+
$project: {
|
|
1529
|
+
fileDate: 1,
|
|
1530
|
+
clientId: 1,
|
|
1531
|
+
clientName: 1,
|
|
1532
|
+
queueName: 1,
|
|
1533
|
+
installedStore: 1,
|
|
1534
|
+
totalFilesCount: 1,
|
|
1535
|
+
moduleType: 1,
|
|
1536
|
+
notAssignedCount: { $ifNull: [ 0, 0 ] },
|
|
1537
|
+
clientStatus: { $ifNull: [ '', '' ] },
|
|
1538
|
+
},
|
|
1539
|
+
},
|
|
1540
|
+
{
|
|
1541
|
+
$lookup: {
|
|
1542
|
+
'from': 'binaryAudit',
|
|
1543
|
+
'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalFilesCount' },
|
|
1544
|
+
'pipeline': [
|
|
1545
|
+
|
|
1546
|
+
{
|
|
1547
|
+
$match: {
|
|
1548
|
+
$expr: {
|
|
1549
|
+
$and: storeAuditFilter,
|
|
1550
|
+
},
|
|
1551
|
+
},
|
|
1552
|
+
},
|
|
1553
|
+
{
|
|
1554
|
+
$project: {
|
|
1555
|
+
completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
|
|
1556
|
+
notAssignedStores: { $cond: [ { $eq: [ '$status', 'not_assign' ] }, 1, 0 ] },
|
|
1557
|
+
inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
|
|
1558
|
+
},
|
|
1559
|
+
},
|
|
1560
|
+
{
|
|
1561
|
+
$group: {
|
|
1562
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate' },
|
|
1563
|
+
completedStores: { $sum: '$completedStores' },
|
|
1564
|
+
inprogressStores: { $sum: '$inprogressStores' },
|
|
1565
|
+
notAssignedStores: { $sum: '$notAssignedStores' },
|
|
1566
|
+
fileCount: { $sum: 1 },
|
|
1567
|
+
},
|
|
1568
|
+
},
|
|
1569
|
+
{
|
|
1570
|
+
$project: {
|
|
1571
|
+
_id: 0,
|
|
1572
|
+
completedStores: 1,
|
|
1573
|
+
inprogressStores: 1,
|
|
1574
|
+
notAssignedStores: 1,
|
|
1575
|
+
fileCount: { $ifNull: [ '$fileCount', 0 ] },
|
|
1576
|
+
completionPercentage: { $ifNull: [
|
|
1577
|
+
{
|
|
1578
|
+
$round: [ {
|
|
1579
|
+
$multiply: [
|
|
1580
|
+
100, {
|
|
1581
|
+
$divide: [
|
|
1582
|
+
'$completedStores', '$$totalAuditFiles',
|
|
1583
|
+
],
|
|
1584
|
+
},
|
|
1585
|
+
],
|
|
1586
|
+
}, 1 ],
|
|
1587
|
+
|
|
1588
|
+
},
|
|
1589
|
+
0,
|
|
1590
|
+
],
|
|
1591
|
+
},
|
|
1592
|
+
},
|
|
1593
|
+
},
|
|
1594
|
+
], 'as': 'binaryAudit',
|
|
1595
|
+
},
|
|
1596
|
+
},
|
|
1597
|
+
{
|
|
1598
|
+
$unwind: {
|
|
1599
|
+
path: '$binaryAudit',
|
|
1600
|
+
preserveNullAndEmptyArrays: true,
|
|
1601
|
+
},
|
|
1602
|
+
},
|
|
1603
|
+
{
|
|
1604
|
+
$project: {
|
|
1605
|
+
_id: 0,
|
|
1606
|
+
fileDate: 1,
|
|
1607
|
+
clientId: 1,
|
|
1608
|
+
clientName: 1,
|
|
1609
|
+
totalFilesCount: 1,
|
|
1610
|
+
moduleType: 1,
|
|
1611
|
+
installedStore: 1,
|
|
1612
|
+
// notAssignedStores: '$binaryAudit.notAssignedStores',
|
|
1613
|
+
inprogressStoresCount: '$binaryAudit.inprogressStores',
|
|
1614
|
+
// fileCount: '$binaryAudit.fileCount',
|
|
1615
|
+
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
|
|
1616
|
+
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 ] } ] }
|
|
1617
|
+
completedStores: '$binaryAudit.completedStores',
|
|
1618
|
+
completionPercentage: '$binaryAudit.completionPercentage',
|
|
1619
|
+
|
|
1620
|
+
},
|
|
1621
|
+
},
|
|
1622
|
+
];
|
|
1623
|
+
|
|
1624
|
+
if ( inputData?.filterByStatus?.length> 0 ) {
|
|
1625
|
+
query.push(
|
|
1626
|
+
{
|
|
1627
|
+
$match: { clientStatus: { $in: inputData.filterByStatus } },
|
|
1628
|
+
},
|
|
1629
|
+
|
|
1630
|
+
);
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
1634
|
+
query.push( {
|
|
1635
|
+
$match: {
|
|
1636
|
+
$or: [
|
|
1637
|
+
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1638
|
+
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1639
|
+
{ moduleType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1640
|
+
{ clientStatus: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1641
|
+
],
|
|
1642
|
+
|
|
1643
|
+
},
|
|
1644
|
+
} );
|
|
1645
|
+
}
|
|
1646
|
+
if ( inputData.sortColumnName ) {
|
|
1647
|
+
const sortBy = inputData.sortBy || -1;
|
|
1648
|
+
const sortColumn = inputData.sortColumnName;
|
|
1649
|
+
query.push( {
|
|
1650
|
+
$sort: { [sortColumn]: sortBy },
|
|
1651
|
+
},
|
|
1652
|
+
);
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
const count = await aggregateTraxAuditData( query );
|
|
1656
|
+
logger.info( { count: count } );
|
|
1657
|
+
if ( count.length == 0 ) {
|
|
1658
|
+
return res.sendError( 'No Data Found', 204 );
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
query.push(
|
|
1662
|
+
{ $skip: offset },
|
|
1663
|
+
{ $limit: limit },
|
|
1664
|
+
);
|
|
1665
|
+
if ( inputData.isExport ) {
|
|
1666
|
+
query.push(
|
|
1667
|
+
{
|
|
1668
|
+
$project: {
|
|
1669
|
+
'_id': 0,
|
|
1670
|
+
'File Date': '$fileDate',
|
|
1671
|
+
'Client Name': '$clientName',
|
|
1672
|
+
'Client Id': '$clientId',
|
|
1673
|
+
'Product Type': '$moduleType',
|
|
1674
|
+
'Completed Percentage': '$completionPercentage',
|
|
1675
|
+
'Installed Stores': '$installedStore',
|
|
1676
|
+
'Audit Stores': '$totalFilesCount',
|
|
1677
|
+
'Inprogress Stores': '$inprogressStoresCount',
|
|
1678
|
+
'Not Assigned': '$notAssignedCount',
|
|
1679
|
+
// 'Not Assigned Stores': '$notAssignedStores',
|
|
1680
|
+
'Completed': '$completedStores',
|
|
1681
|
+
'Status': '$clientStatus',
|
|
1682
|
+
},
|
|
1683
|
+
},
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
logger.info( { query: query } );
|
|
1688
|
+
const result = await aggregateTraxAuditData( query );
|
|
1689
|
+
if ( result.length == 0 ) {
|
|
1690
|
+
return res.sendError( 'No Data Found', 204 );
|
|
1691
|
+
}
|
|
1692
|
+
if ( inputData.isExport ) {
|
|
1693
|
+
await download( result, res );
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
1697
|
+
} catch ( error ) {
|
|
1698
|
+
const err = error.error || 'Internal Server Error';
|
|
1699
|
+
logger.info( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
1700
|
+
return res.sendError( err, 500 );
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
export async function storeMetrics( req, res ) {
|
|
1705
|
+
try {
|
|
1706
|
+
const inputData = req.body;
|
|
1707
|
+
const limit = inputData.limit || 10;
|
|
1708
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
1709
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
1710
|
+
let filter = [
|
|
1711
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
1712
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
1713
|
+
{ moduleType: { $eq: inputData.moduleType } },
|
|
1714
|
+
|
|
1715
|
+
];
|
|
1716
|
+
if ( inputData.filterByClientId && inputData.filterByClientId?.length > 0 ) {
|
|
1717
|
+
filter.push( { clientId: { $in: inputData.filterByClientId } } );
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
if ( inputData.filterByStoreId && inputData.filterByStoreId?.length > 0 ) {
|
|
1721
|
+
filter.push( { storeId: { $in: inputData.filterByStoreId } } );
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
|
|
1725
|
+
filter.push( { status: { $in: inputData.filterByStatus } } );
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
|
|
1729
|
+
filter.push( { auditType: { $in: inputData.filterByAuditType } } );
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
|
|
1733
|
+
const query = [
|
|
1734
|
+
{
|
|
1735
|
+
$match: {
|
|
1736
|
+
$and: filter,
|
|
1737
|
+
},
|
|
1738
|
+
},
|
|
1739
|
+
|
|
1740
|
+
{
|
|
1741
|
+
$lookup: {
|
|
1742
|
+
from: 'stores',
|
|
1743
|
+
let: { storeId: '$storeId' },
|
|
1744
|
+
pipeline: [
|
|
1745
|
+
{
|
|
1746
|
+
$match: {
|
|
1747
|
+
$expr: {
|
|
1748
|
+
$eq: [ '$storeId', '$$storeId' ],
|
|
1749
|
+
},
|
|
1750
|
+
},
|
|
1751
|
+
},
|
|
1752
|
+
{
|
|
1753
|
+
$project: {
|
|
1754
|
+
_id: 0,
|
|
1755
|
+
storeName: 1,
|
|
1756
|
+
},
|
|
1757
|
+
},
|
|
1758
|
+
], as: 'stores',
|
|
1759
|
+
},
|
|
1760
|
+
},
|
|
1761
|
+
{
|
|
1762
|
+
$unwind: {
|
|
1763
|
+
path: '$stores',
|
|
1764
|
+
preserveNullAndEmptyArrays: true,
|
|
1765
|
+
},
|
|
1766
|
+
},
|
|
1767
|
+
{
|
|
1768
|
+
$project: {
|
|
1769
|
+
_id: 0,
|
|
1770
|
+
fileDate: 1,
|
|
1771
|
+
storeId: 1,
|
|
1772
|
+
storeName: '$stores.storeName',
|
|
1773
|
+
clientName: '',
|
|
1774
|
+
clientId: 1,
|
|
1775
|
+
moduleType: 1,
|
|
1776
|
+
tempId: 1,
|
|
1777
|
+
streamName: 1,
|
|
1778
|
+
question: 1,
|
|
1779
|
+
answer: 1,
|
|
1780
|
+
// userId: {
|
|
1781
|
+
// $arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], //need to check if no data
|
|
1782
|
+
// },
|
|
1783
|
+
auditType: 1,
|
|
1784
|
+
beforeCount: 1,
|
|
1785
|
+
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
1786
|
+
accuracy: { $cond: [ { $eq: [ '$status', 'completed' ] }, { $round: [
|
|
1787
|
+
{
|
|
1788
|
+
$multiply: [ { $divide: [ '$afterCount', '$beforeCount' ] }, 100 ],
|
|
1789
|
+
}, 1,
|
|
1790
|
+
],
|
|
1791
|
+
}, null ] },
|
|
1792
|
+
timeSpent: 1,
|
|
1793
|
+
status: 1,
|
|
1794
|
+
},
|
|
1795
|
+
},
|
|
1796
|
+
{
|
|
1797
|
+
$lookup: {
|
|
1798
|
+
from: 'users',
|
|
1799
|
+
let: { userId: '$userId' },
|
|
1800
|
+
pipeline: [
|
|
1801
|
+
{
|
|
1802
|
+
$match: {
|
|
1803
|
+
$expr: {
|
|
1804
|
+
$eq: [ '$_id', '$$userId' ],
|
|
1805
|
+
},
|
|
1806
|
+
},
|
|
1807
|
+
},
|
|
1808
|
+
{
|
|
1809
|
+
$project: {
|
|
1810
|
+
_id: 0,
|
|
1811
|
+
userName: 1,
|
|
1812
|
+
userEmail: '$email',
|
|
1813
|
+
},
|
|
1814
|
+
},
|
|
1815
|
+
], as: 'users',
|
|
1816
|
+
},
|
|
1817
|
+
},
|
|
1818
|
+
{
|
|
1819
|
+
$unwind: {
|
|
1820
|
+
path: '$users',
|
|
1821
|
+
preserveNullAndEmptyArrays: true,
|
|
1822
|
+
},
|
|
1823
|
+
},
|
|
1824
|
+
{
|
|
1825
|
+
$lookup: {
|
|
1826
|
+
from: 'clients',
|
|
1827
|
+
let: { clientId: '$clientId' },
|
|
1828
|
+
pipeline: [
|
|
1829
|
+
{
|
|
1830
|
+
$match: {
|
|
1831
|
+
$expr: {
|
|
1832
|
+
$eq: [ '$clientId', '$$clientId' ],
|
|
1833
|
+
},
|
|
1834
|
+
},
|
|
1835
|
+
},
|
|
1836
|
+
{
|
|
1837
|
+
$project: {
|
|
1838
|
+
_id: 0,
|
|
1839
|
+
clientName: 1,
|
|
1840
|
+
},
|
|
1841
|
+
},
|
|
1842
|
+
], as: 'client',
|
|
1843
|
+
},
|
|
1844
|
+
},
|
|
1845
|
+
{
|
|
1846
|
+
$unwind: {
|
|
1847
|
+
path: '$client',
|
|
1848
|
+
preserveNullAndEmptyArrays: true,
|
|
1849
|
+
},
|
|
1850
|
+
},
|
|
1851
|
+
{
|
|
1852
|
+
$project: {
|
|
1853
|
+
_id: 0,
|
|
1854
|
+
fileDate: 1,
|
|
1855
|
+
storeId: 1,
|
|
1856
|
+
storeName: 1,
|
|
1857
|
+
userName: '$users.userName',
|
|
1858
|
+
userEmail: '$users.userEmail',
|
|
1859
|
+
clientId: 1,
|
|
1860
|
+
clientName: '$client.clientName',
|
|
1861
|
+
tempId: 1,
|
|
1862
|
+
streamName: 1,
|
|
1863
|
+
question: 1,
|
|
1864
|
+
answer: 1,
|
|
1865
|
+
moduleType: 1,
|
|
1866
|
+
auditType: 1,
|
|
1867
|
+
beforeCount: 1,
|
|
1868
|
+
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
1869
|
+
accuracy: { $cond: [ { $eq: [ '$status', 'completed' ] }, { $round: [
|
|
1870
|
+
{
|
|
1871
|
+
$multiply: [ { $divide: [ '$afterCount', '$beforeCount' ] }, 100 ],
|
|
1872
|
+
}, 1,
|
|
1873
|
+
],
|
|
1874
|
+
}, null ] },
|
|
1875
|
+
timeSpent: {
|
|
1876
|
+
|
|
1877
|
+
$cond: [
|
|
1878
|
+
{ $lt: [ '$timeSpent', 60 ] }, // Case 1: If less than 60 seconds
|
|
1879
|
+
{ $concat: [ { $toString: '$timeSpent' }, ' sec' ] },
|
|
1880
|
+
{
|
|
1881
|
+
$cond: [
|
|
1882
|
+
{ $lt: [ '$timeSpent', 3600 ] }, // Case 2: If less than 60 minutes (3600 seconds)
|
|
1883
|
+
{
|
|
1884
|
+
$concat: [
|
|
1885
|
+
{ $toString: { $round: [ { $divide: [ '$timeSpent', 60 ] }, 1 ] } }, // Convert to minutes
|
|
1886
|
+
' min',
|
|
1887
|
+
],
|
|
1888
|
+
},
|
|
1889
|
+
{
|
|
1890
|
+
$concat: [
|
|
1891
|
+
{ $toString: { $round: [ { $divide: [ '$timeSpent', 3600 ] }, 1 ] } }, // Convert to hours
|
|
1892
|
+
' hr',
|
|
1893
|
+
],
|
|
1894
|
+
},
|
|
1895
|
+
],
|
|
1896
|
+
},
|
|
1897
|
+
],
|
|
1898
|
+
|
|
1899
|
+
},
|
|
1900
|
+
status: 1,
|
|
1901
|
+
},
|
|
1902
|
+
},
|
|
1903
|
+
|
|
1904
|
+
];
|
|
1905
|
+
|
|
1906
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
1907
|
+
query.push( {
|
|
1908
|
+
$match: {
|
|
1909
|
+
$or: [
|
|
1910
|
+
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1911
|
+
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1912
|
+
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1913
|
+
{ storeName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1914
|
+
{ userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1915
|
+
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1916
|
+
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1917
|
+
{ moduleType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1918
|
+
{ tempId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1919
|
+
{ question: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1920
|
+
{ answer: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1921
|
+
],
|
|
1922
|
+
},
|
|
1923
|
+
} );
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
if ( inputData.sortColumnName ) {
|
|
1927
|
+
const sortBy = inputData.sortBy || -1;
|
|
1928
|
+
const sortColumn = inputData.sortColumnName;
|
|
1929
|
+
query.push( {
|
|
1930
|
+
$sort: { [sortColumn]: sortBy },
|
|
1931
|
+
},
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1934
|
+
const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1935
|
+
|
|
1936
|
+
if ( count.length == 0 ) {
|
|
1937
|
+
return res.sendError( 'No data Found', 204 );
|
|
1938
|
+
}
|
|
1939
|
+
if ( !inputData.isExport ) {
|
|
1940
|
+
query.push( {
|
|
1941
|
+
$skip: offset,
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
$limit: limit,
|
|
1945
|
+
} );
|
|
1946
|
+
} else {
|
|
1947
|
+
query.push( { $limit: 10000 } );
|
|
1948
|
+
}
|
|
1949
|
+
const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1950
|
+
if ( inputData.isExport ) {
|
|
1951
|
+
const exportdata = [];
|
|
1952
|
+
result.forEach( ( element ) => {
|
|
1953
|
+
if ( element.moduleType == 'zone' ) {
|
|
1954
|
+
exportdata.push( {
|
|
1955
|
+
'File Date': element.fileDate,
|
|
1956
|
+
'Store ID': element.storeId,
|
|
1957
|
+
'Store Name': element.storeName,
|
|
1958
|
+
'Client Id': element.clientId,
|
|
1959
|
+
'Client Name': element.clientName,
|
|
1960
|
+
'Customer Id': element.tempId,
|
|
1961
|
+
'Question': element.question,
|
|
1962
|
+
'Answer': element.answer,
|
|
1963
|
+
'User Name': element.userName,
|
|
1964
|
+
'User Email': element.userEmail,
|
|
1965
|
+
'Audit Type': element.auditType,
|
|
1966
|
+
'Accuracy': element.accuracy,
|
|
1967
|
+
'Time Spent': element.timeSpent,
|
|
1968
|
+
'Status': element.status,
|
|
1969
|
+
} );
|
|
1970
|
+
} else {
|
|
1971
|
+
exportdata.push( {
|
|
1972
|
+
'File Date': element.fileDate,
|
|
1973
|
+
'Store ID': element.storeId,
|
|
1974
|
+
'Store Name': element.storeName,
|
|
1975
|
+
'Client Id': element.clientId,
|
|
1976
|
+
'Client Name': element.clientName,
|
|
1977
|
+
'User Name': element.userName,
|
|
1978
|
+
'Customer Id': element.tempId,
|
|
1979
|
+
'Question': element.question,
|
|
1980
|
+
'Answer': element.answer,
|
|
1981
|
+
'User Email': element.userEmail,
|
|
1982
|
+
'Audit Type': element.auditType,
|
|
1983
|
+
'Accuracy': element.accuracy,
|
|
1984
|
+
'Time Spent': element.timeSpent,
|
|
1985
|
+
'Status': element.status,
|
|
1986
|
+
} );
|
|
1987
|
+
}
|
|
1988
|
+
} );
|
|
1989
|
+
await download( exportdata, res );
|
|
1990
|
+
return;
|
|
1991
|
+
}
|
|
1992
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
1993
|
+
} catch ( error ) {
|
|
1994
|
+
const err = error.message || 'Internal Server Error';
|
|
1995
|
+
logger.error( { error: error, data: req.body, function: 'storeMetrics' } );
|
|
1996
|
+
return res.sendError( err, 500 );
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
export async function userMetrics( req, res ) {
|
|
2001
|
+
try {
|
|
2002
|
+
const inputData = req.body;
|
|
2003
|
+
const limit = inputData.limit || 10;
|
|
2004
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
2005
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
2006
|
+
const dateRangeUpdatedAt = await getDateWithCustomizeTime( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
2007
|
+
let filter = [
|
|
2008
|
+
{ moduleType: { $eq: inputData.moduleType } },
|
|
2009
|
+
];
|
|
2010
|
+
if ( inputData.dateType == 'auditedDate' ) {
|
|
2011
|
+
filter.push(
|
|
2012
|
+
{ updatedAt: { $gte: dateRangeUpdatedAt.start } },
|
|
2013
|
+
{ updatedAt: { $lte: dateRangeUpdatedAt.end } },
|
|
2014
|
+
|
|
2015
|
+
);
|
|
2016
|
+
} else {
|
|
2017
|
+
filter.push(
|
|
2018
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
2019
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
2020
|
+
|
|
2021
|
+
);
|
|
2022
|
+
}
|
|
2023
|
+
if ( inputData?.filterByStatus?.length> 0 ) {
|
|
2024
|
+
filter.push(
|
|
2025
|
+
{ auditStatus: { $in: inputData.filterByStatus } },
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
2028
|
+
if ( inputData?.filterByUser?.length> 0 ) {
|
|
2029
|
+
const temp = inputData.filterByUser.map( ( item ) => new mongoose.Types.ObjectId( item ) );
|
|
2030
|
+
logger.info( { temp: temp } );
|
|
2031
|
+
filter.push(
|
|
2032
|
+
{ userId: { $in: temp } },
|
|
2033
|
+
);
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
const query = [
|
|
2037
|
+
{
|
|
2038
|
+
$match: {
|
|
2039
|
+
$and: filter,
|
|
2040
|
+
},
|
|
2041
|
+
},
|
|
2042
|
+
{
|
|
2043
|
+
$project: {
|
|
2044
|
+
userId: 1,
|
|
2045
|
+
fileDate: 1,
|
|
2046
|
+
startTime: 1,
|
|
2047
|
+
endTime: 1,
|
|
2048
|
+
streamName: 1,
|
|
2049
|
+
tempId: 1,
|
|
2050
|
+
question: 1,
|
|
2051
|
+
answer: 1,
|
|
2052
|
+
totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
|
|
2053
|
+
beforeCount: 1,
|
|
2054
|
+
afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
|
|
2055
|
+
},
|
|
2056
|
+
},
|
|
2057
|
+
{
|
|
2058
|
+
$group: {
|
|
2059
|
+
_id: { userId: '$userId', fileDate: '$fileDate' },
|
|
2060
|
+
userId: { $first: '$userId' },
|
|
2061
|
+
fileDate: { $first: '$fileDate' },
|
|
2062
|
+
totalCompletedFiles: { $sum: '$totalCompletedFiles' },
|
|
2063
|
+
beforeCount: { $sum: '$beforeCount' },
|
|
2064
|
+
afterCount: { $sum: '$afterCount' },
|
|
2065
|
+
checkIntime: { $first: '$startTime' },
|
|
2066
|
+
checkOutTime: { $last: '$endTime' },
|
|
2067
|
+
streamName: { $last: '$streamName' },
|
|
2068
|
+
tempId: { $last: '$tempId' },
|
|
2069
|
+
question: { $last: '$question' },
|
|
2070
|
+
answer: { $last: '$answer' },
|
|
2071
|
+
|
|
2072
|
+
},
|
|
2073
|
+
},
|
|
2074
|
+
{
|
|
2075
|
+
$project: {
|
|
2076
|
+
_id: 0,
|
|
2077
|
+
userId: 1,
|
|
2078
|
+
fileDate: 1,
|
|
2079
|
+
totalCompletedFiles: 1,
|
|
2080
|
+
beforeCount: 1,
|
|
2081
|
+
afterCount: 1,
|
|
2082
|
+
streamName: 1,
|
|
2083
|
+
tempId: 1,
|
|
2084
|
+
question: 1,
|
|
2085
|
+
answer: 1,
|
|
2086
|
+
mappingPerc: { $round: [
|
|
2087
|
+
{ $multiply: [
|
|
2088
|
+
{ $divide: [ '$afterCount', '$beforeCount' ] }, 100,
|
|
2089
|
+
] }, 2,
|
|
2090
|
+
] },
|
|
2091
|
+
checkIntime: 1,
|
|
2092
|
+
checkOutTime: 1,
|
|
2093
|
+
differenceInSeconds: {
|
|
2094
|
+
$divide: [ { $subtract: [ '$checkOutTime', '$checkIntime' ] }, 1000 ],
|
|
2095
|
+
},
|
|
2096
|
+
},
|
|
2097
|
+
},
|
|
2098
|
+
{
|
|
2099
|
+
$project: {
|
|
2100
|
+
userId: 1,
|
|
2101
|
+
fileDate: 1,
|
|
2102
|
+
totalCompletedFiles: 1,
|
|
2103
|
+
beforeCount: 1,
|
|
2104
|
+
afterCount: 1,
|
|
2105
|
+
checkIntime: 1,
|
|
2106
|
+
checkOutTime: 1,
|
|
2107
|
+
mappingPerc: 1,
|
|
2108
|
+
streamName: 1,
|
|
2109
|
+
tempId: 1,
|
|
2110
|
+
question: 1,
|
|
2111
|
+
answer: 1,
|
|
2112
|
+
hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
|
|
2113
|
+
minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
|
|
2114
|
+
seconds: { $mod: [ '$differenceInSeconds', 60 ] },
|
|
2115
|
+
},
|
|
2116
|
+
},
|
|
2117
|
+
{
|
|
2118
|
+
$project: {
|
|
2119
|
+
event: 1,
|
|
2120
|
+
userId: 1,
|
|
2121
|
+
fileDate: 1,
|
|
2122
|
+
totalCompletedFiles: 1,
|
|
2123
|
+
beforeCount: 1,
|
|
2124
|
+
afterCount: 1,
|
|
2125
|
+
checkIntime: 1,
|
|
2126
|
+
checkOutTime: 1,
|
|
2127
|
+
mappingPerc: 1,
|
|
2128
|
+
streamName: 1,
|
|
2129
|
+
tempId: 1,
|
|
2130
|
+
question: 1,
|
|
2131
|
+
answer: 1,
|
|
2132
|
+
hours: {
|
|
2133
|
+
$cond: {
|
|
2134
|
+
if: { $lt: [ '$hours', 10 ] },
|
|
2135
|
+
then: { $concat: [ '0', { $toString: { $round: [ '$hours', 0 ] } } ] },
|
|
2136
|
+
else: { $toString: { $round: [ '$hours', 0 ] } },
|
|
2137
|
+
},
|
|
2138
|
+
},
|
|
2139
|
+
minutes: {
|
|
2140
|
+
$cond: {
|
|
2141
|
+
if: { $lt: [ '$minutes', 10 ] },
|
|
2142
|
+
then: { $concat: [ '0', { $toString: { $round: [ '$minutes', 0 ] } } ] },
|
|
2143
|
+
else: { $toString: { $round: [ '$minutes', 0 ] } },
|
|
2144
|
+
},
|
|
2145
|
+
},
|
|
2146
|
+
seconds: {
|
|
2147
|
+
$cond: {
|
|
2148
|
+
if: { $lt: [ '$seconds', 10 ] },
|
|
2149
|
+
then: { $concat: [ '0', { $toString: { $round: [ '$seconds', 0 ] } } ] },
|
|
2150
|
+
else: { $toString: { $round: [ '$seconds', 0 ] } },
|
|
2151
|
+
},
|
|
2152
|
+
},
|
|
2153
|
+
|
|
2154
|
+
},
|
|
2155
|
+
},
|
|
2156
|
+
{
|
|
2157
|
+
$project: {
|
|
2158
|
+
event: 1,
|
|
2159
|
+
userId: 1,
|
|
2160
|
+
fileDate: 1,
|
|
2161
|
+
totalCompletedFiles: 1,
|
|
2162
|
+
beforeCount: 1,
|
|
2163
|
+
afterCount: 1,
|
|
2164
|
+
checkIntime: 1,
|
|
2165
|
+
zoneName: 1,
|
|
2166
|
+
checkOutTime: 1,
|
|
2167
|
+
mappingPerc: 1,
|
|
2168
|
+
streamName: 1,
|
|
2169
|
+
tempId: 1,
|
|
2170
|
+
question: 1,
|
|
2171
|
+
answer: 1,
|
|
2172
|
+
workingHours: {
|
|
2173
|
+
$concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
|
|
2174
|
+
},
|
|
2175
|
+
},
|
|
2176
|
+
},
|
|
2177
|
+
{
|
|
2178
|
+
$lookup: {
|
|
2179
|
+
from: 'users',
|
|
2180
|
+
let: { userId: '$userId' },
|
|
2181
|
+
pipeline: [
|
|
2182
|
+
{
|
|
2183
|
+
$match: {
|
|
2184
|
+
$expr: {
|
|
2185
|
+
$eq: [ '$_id', '$$userId' ],
|
|
2186
|
+
},
|
|
2187
|
+
},
|
|
2188
|
+
},
|
|
2189
|
+
{
|
|
2190
|
+
$project: {
|
|
2191
|
+
_id: 0,
|
|
2192
|
+
userName: 1,
|
|
2193
|
+
},
|
|
2194
|
+
},
|
|
2195
|
+
], as: 'userInfo',
|
|
2196
|
+
},
|
|
2197
|
+
},
|
|
2198
|
+
{
|
|
2199
|
+
$unwind: {
|
|
2200
|
+
path: '$userInfo', preserveNullAndEmptyArrays: true,
|
|
2201
|
+
},
|
|
2202
|
+
},
|
|
2203
|
+
{
|
|
2204
|
+
$project: {
|
|
2205
|
+
event: 1,
|
|
2206
|
+
userName: '$userInfo.userName',
|
|
2207
|
+
userId: 1,
|
|
2208
|
+
fileDate: 1,
|
|
2209
|
+
totalCompletedFiles: 1,
|
|
2210
|
+
beforeCount: 1,
|
|
2211
|
+
afterCount: 1,
|
|
2212
|
+
mappingPerc: 1,
|
|
2213
|
+
streamName: 1,
|
|
2214
|
+
tempId: 1,
|
|
2215
|
+
question: 1,
|
|
2216
|
+
answer: 1,
|
|
2217
|
+
checkIntime: {
|
|
2218
|
+
$dateToString: {
|
|
2219
|
+
format: '%Y-%m-%d %H:%M:%S',
|
|
2220
|
+
date: '$checkIntime',
|
|
2221
|
+
timezone: 'Asia/Kolkata',
|
|
2222
|
+
},
|
|
2223
|
+
},
|
|
2224
|
+
checkOutTime: {
|
|
2225
|
+
$dateToString: {
|
|
2226
|
+
format: '%Y-%m-%d %H:%M:%S',
|
|
2227
|
+
date: '$checkOutTime',
|
|
2228
|
+
timezone: 'Asia/Kolkata',
|
|
2229
|
+
},
|
|
2230
|
+
},
|
|
2231
|
+
workingHours: 1,
|
|
2232
|
+
},
|
|
2233
|
+
},
|
|
2234
|
+
];
|
|
2235
|
+
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
2236
|
+
query.push( {
|
|
2237
|
+
$match: {
|
|
2238
|
+
$or: [
|
|
2239
|
+
{ userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2240
|
+
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2241
|
+
],
|
|
2242
|
+
|
|
2243
|
+
},
|
|
2244
|
+
} );
|
|
2245
|
+
}
|
|
2246
|
+
if ( inputData.sortColumnName ) {
|
|
2247
|
+
const sortBy = inputData.sortBy || -1;
|
|
2248
|
+
const sortColumn = inputData.sortColumnName;
|
|
2249
|
+
query.push( {
|
|
2250
|
+
$sort: { [sortColumn]: sortBy },
|
|
2251
|
+
},
|
|
2252
|
+
);
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2256
|
+
if ( count.length == 0 ) {
|
|
2257
|
+
return res.sendError( 'No Data Found', 204 );
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
query.push(
|
|
2261
|
+
{ $skip: offset },
|
|
2262
|
+
{ $limit: limit },
|
|
2263
|
+
);
|
|
2264
|
+
if ( inputData.isExport ) {
|
|
2265
|
+
query.push(
|
|
2266
|
+
{
|
|
2267
|
+
$project: {
|
|
2268
|
+
'_id': 0,
|
|
2269
|
+
'File Date': '$fileDate',
|
|
2270
|
+
'User Name': '$userName',
|
|
2271
|
+
'Total Completed Files Count': '$totalCompletedFiles',
|
|
2272
|
+
'Total Before Count': '$beforeCount',
|
|
2273
|
+
'Total After Count': '$afterCount',
|
|
2274
|
+
'check Intime': '$checkIntime',
|
|
2275
|
+
'check OutTime': '$checkOutTime',
|
|
2276
|
+
'working Hours': '$workingHours',
|
|
2277
|
+
'Mapping Percentage': '$mappingPerc',
|
|
2278
|
+
},
|
|
2279
|
+
},
|
|
2280
|
+
);
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
|
|
2284
|
+
const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2285
|
+
if ( inputData.isExport ) {
|
|
2286
|
+
await download( result, res );
|
|
2287
|
+
return;
|
|
2288
|
+
}
|
|
2289
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
2290
|
+
} catch ( error ) {
|
|
2291
|
+
const err = error.error || 'Internal Server Error';
|
|
2292
|
+
logger.info( { error: error, message: req.body, function: 'userMetrics' } );
|
|
2293
|
+
return res.sendError( err, 500 );
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema } from '../dtos/traxAudit.dtos.js';
|
|
2
|
+
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema } from '../dtos/traxAudit.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const traxAuditDocs = {
|
|
5
5
|
|
|
@@ -111,4 +111,71 @@ export const traxAuditDocs = {
|
|
|
111
111
|
},
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
|
+
'/v3/trax-audit/metrics/client-metrics': {
|
|
115
|
+
post: {
|
|
116
|
+
tags: [ 'Trax Audit' ],
|
|
117
|
+
description: `Get list of client wise details with date range`,
|
|
118
|
+
operationId: 'metrics/client-metrics',
|
|
119
|
+
parameters: {},
|
|
120
|
+
requestBody: {
|
|
121
|
+
content: {
|
|
122
|
+
'application/json': {
|
|
123
|
+
schema: j2s( clientMetricsSchema ).swagger,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
responses: {
|
|
128
|
+
200: { description: 'Successful' },
|
|
129
|
+
401: { description: 'Unauthorized User' },
|
|
130
|
+
422: { description: 'Field Error' },
|
|
131
|
+
500: { description: 'Server Error' },
|
|
132
|
+
204: { description: 'Not Found' },
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
'/v3/trax-audit/metrics/store-metrics': {
|
|
138
|
+
post: {
|
|
139
|
+
tags: [ 'Trax Audit' ],
|
|
140
|
+
description: `Get list of store wise details with date range and client Id`,
|
|
141
|
+
operationId: 'metrics/store-metrics',
|
|
142
|
+
parameters: {},
|
|
143
|
+
requestBody: {
|
|
144
|
+
content: {
|
|
145
|
+
'application/json': {
|
|
146
|
+
schema: j2s( storeMetricsSchema ).swagger,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
responses: {
|
|
151
|
+
200: { description: 'Successful' },
|
|
152
|
+
401: { description: 'Unauthorized User' },
|
|
153
|
+
422: { description: 'Field Error' },
|
|
154
|
+
500: { description: 'Server Error' },
|
|
155
|
+
204: { description: 'Not Found' },
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
'/v3/trax-audit/metrics/user-metrics': {
|
|
160
|
+
post: {
|
|
161
|
+
tags: [ 'Trax Audit' ],
|
|
162
|
+
description: `Get list of file wise details with date range and users`,
|
|
163
|
+
operationId: 'metrics/user-metrics',
|
|
164
|
+
parameters: {},
|
|
165
|
+
requestBody: {
|
|
166
|
+
content: {
|
|
167
|
+
'application/json': {
|
|
168
|
+
schema: j2s( userMetricsSchema ).swagger,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
responses: {
|
|
173
|
+
200: { description: 'Successful' },
|
|
174
|
+
401: { description: 'Unauthorized User' },
|
|
175
|
+
422: { description: 'Field Error' },
|
|
176
|
+
500: { description: 'Server Error' },
|
|
177
|
+
204: { description: 'Not Found' },
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
114
181
|
};
|
|
@@ -73,6 +73,7 @@ export const saveSchema = joi.object(
|
|
|
73
73
|
question: joi.string().optional(),
|
|
74
74
|
streamName: joi.string().optional(),
|
|
75
75
|
answer: joi.string().required(),
|
|
76
|
+
userComments: joi.string().required(),
|
|
76
77
|
},
|
|
77
78
|
);
|
|
78
79
|
|
|
@@ -121,3 +122,65 @@ export const userAuditHistorySchema = joi.object(
|
|
|
121
122
|
export const userAuditHistoryValid = {
|
|
122
123
|
body: userAuditHistorySchema,
|
|
123
124
|
};
|
|
125
|
+
|
|
126
|
+
export const clientMetricsSchema = joi.object(
|
|
127
|
+
{
|
|
128
|
+
fromDate: joi.string().required(),
|
|
129
|
+
toDate: joi.string().required(),
|
|
130
|
+
searchValue: joi.string().optional().allow( '' ),
|
|
131
|
+
moduleType: joi.string().required(),
|
|
132
|
+
filterByClient: joi.array().required(),
|
|
133
|
+
filterByStatus: joi.array().optional(),
|
|
134
|
+
sortColumnName: joi.string().optional(),
|
|
135
|
+
sortBy: joi.number().optional(),
|
|
136
|
+
limit: joi.number().optional(),
|
|
137
|
+
offset: joi.number().optional(),
|
|
138
|
+
isExport: joi.boolean().optional(),
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
export const clientMetricsValid = {
|
|
143
|
+
body: clientMetricsSchema,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const storeMetricsSchema = joi.object(
|
|
147
|
+
{
|
|
148
|
+
fromDate: joi.string().required(),
|
|
149
|
+
toDate: joi.string().required(),
|
|
150
|
+
searchValue: joi.string().optional().allow( '' ),
|
|
151
|
+
filterByClientId: joi.array().required(),
|
|
152
|
+
filterByStoreId: joi.array().optional(),
|
|
153
|
+
filterByStatus: joi.array().optional(),
|
|
154
|
+
filterByAuditType: joi.array().optional(),
|
|
155
|
+
moduleType: joi.string().required(),
|
|
156
|
+
sortColumnName: joi.string().optional(),
|
|
157
|
+
sortBy: joi.number().optional(),
|
|
158
|
+
limit: joi.number().optional(),
|
|
159
|
+
offset: joi.number().optional(),
|
|
160
|
+
isExport: joi.boolean().optional(),
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
export const storeMetricsValid = {
|
|
165
|
+
body: storeMetricsSchema,
|
|
166
|
+
};
|
|
167
|
+
export const userMetricsSchema = joi.object(
|
|
168
|
+
{
|
|
169
|
+
fromDate: joi.string().required(),
|
|
170
|
+
toDate: joi.string().required(),
|
|
171
|
+
dateType: joi.string().required(),
|
|
172
|
+
searchValue: joi.string().optional().allow( '' ),
|
|
173
|
+
filterByUser: joi.array().optional(),
|
|
174
|
+
moduleType: joi.string().optional(),
|
|
175
|
+
filterByStatus: joi.array().optional(),
|
|
176
|
+
sortColumnName: joi.string().optional(),
|
|
177
|
+
sortBy: joi.number().optional(),
|
|
178
|
+
limit: joi.number().optional(),
|
|
179
|
+
offset: joi.number().optional(),
|
|
180
|
+
isExport: joi.boolean().optional(),
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
export const userMetricsValid = {
|
|
185
|
+
body: userMetricsSchema,
|
|
186
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
3
|
-
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid } from '../dtos/traxAudit.dtos.js';
|
|
3
|
+
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid } from '../dtos/traxAudit.dtos.js';
|
|
4
4
|
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
5
|
-
import { getAuditFile, getDetectionAuditFile, saveBinary, userAuditHistory, workSpace } from '../controllers/traxAudit.controllers.js';
|
|
5
|
+
import { clientMetrics, getAuditFile, getDetectionAuditFile, saveBinary, storeMetrics, userAuditHistory, userMetrics, workSpace } from '../controllers/traxAudit.controllers.js';
|
|
6
6
|
import { validateBinaryAudit } from '../validation/traxAuditValidation.js';
|
|
7
7
|
|
|
8
8
|
export const traxAuditRouter = Router();
|
|
@@ -17,10 +17,13 @@ traxAuditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpac
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
// Y/n
|
|
20
|
-
traxAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
|
|
21
|
-
traxAuditRouter.post( '/save-binary-audit', isAllowedSessionHandler, validate( saveValid ), validateBinaryAudit, saveBinary );
|
|
22
|
-
|
|
23
|
-
export default traxAuditRouter;
|
|
20
|
+
traxAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
|
|
21
|
+
traxAuditRouter.post( '/save-binary-audit', isAllowedSessionHandler, validate( saveValid ), validateBinaryAudit, saveBinary );
|
|
24
22
|
|
|
25
23
|
// metrcis
|
|
26
24
|
traxAuditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, validate( userAuditHistoryValid ), userAuditHistory );
|
|
25
|
+
traxAuditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
|
|
26
|
+
traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validate( storeMetricsValid ), storeMetrics );
|
|
27
|
+
traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
|
|
28
|
+
|
|
29
|
+
export default traxAuditRouter;
|