tango-app-api-audit 3.6.16 → 3.6.18
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
|
@@ -1516,7 +1516,7 @@ export async function summaryList( req, res ) {
|
|
|
1516
1516
|
return res.sendError( 'No data', 204 );
|
|
1517
1517
|
}
|
|
1518
1518
|
const temp =[];
|
|
1519
|
-
|
|
1519
|
+
let finalTemp =[];
|
|
1520
1520
|
for ( const [ i, cluster ] of getCluster.entries() ) {
|
|
1521
1521
|
temp.push( cluster );
|
|
1522
1522
|
const getClusterQuery= {
|
|
@@ -1550,21 +1550,24 @@ export async function summaryList( req, res ) {
|
|
|
1550
1550
|
},
|
|
1551
1551
|
},
|
|
1552
1552
|
},
|
|
1553
|
+
|
|
1553
1554
|
};
|
|
1554
|
-
logger.info( { getClusterQuery: getClusterQuery } );
|
|
1555
1555
|
const getResponse = await getOpenSearchData( openSearch.EyeTestInput, getClusterQuery );
|
|
1556
|
-
|
|
1556
|
+
logger.info( { getResponse: getResponse } );
|
|
1557
|
+
if ( getResponse?.body?.aggregations && getResponse?.body?.aggregations?.total_count?.value > 0 ) {
|
|
1557
1558
|
delete temp[i].store;
|
|
1558
1559
|
delete temp[i]._id;
|
|
1560
|
+
|
|
1559
1561
|
temp[i].totalFiles = getResponse?.body?.aggregations?.total_count?.value || 0,
|
|
1560
1562
|
temp[i].completedFiles=getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 0;
|
|
1561
1563
|
temp[i].complianceScore = `${ Math.round( getResponse?.body?.aggregations?.avg_complianceScore?.value || 0 )} %`;
|
|
1562
1564
|
temp[i].trustScore = getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value ==null || getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value == undefined ?'NA':`${Math.round( getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value ) + ' %'}`;
|
|
1565
|
+
finalTemp.push( temp[i] );
|
|
1563
1566
|
}
|
|
1564
1567
|
}
|
|
1565
1568
|
|
|
1566
1569
|
if ( inputData.isExport == true ) {
|
|
1567
|
-
const chunkedMappingData = await chunkArray(
|
|
1570
|
+
const chunkedMappingData = await chunkArray( finalTemp, 10 );
|
|
1568
1571
|
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
1569
1572
|
const exportData = [];
|
|
1570
1573
|
for ( const element of chunk ) {
|
|
@@ -1599,353 +1602,186 @@ export async function summaryList( req, res ) {
|
|
|
1599
1602
|
await download( result, res );
|
|
1600
1603
|
return;
|
|
1601
1604
|
} else {
|
|
1602
|
-
|
|
1605
|
+
if ( finalTemp.length > 0 ) {
|
|
1606
|
+
return res.sendSuccess( { result: finalTemp, count: count || 0 } );
|
|
1607
|
+
} else {
|
|
1608
|
+
return res.sendError( 'no data', 204 );
|
|
1609
|
+
}
|
|
1603
1610
|
}
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
},
|
|
1611
|
+
}
|
|
1612
|
+
let search ={
|
|
1613
|
+
'must': filter,
|
|
1614
|
+
};
|
|
1615
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
1616
|
+
if ( inputData.type&&inputData.type==='remote' ) {
|
|
1617
|
+
search ={
|
|
1618
|
+
'must': filter,
|
|
1619
|
+
'should': [
|
|
1620
|
+
{
|
|
1621
|
+
'wildcard': {
|
|
1622
|
+
'storeName.keyword': {
|
|
1623
|
+
'value': `*${inputData.searchValue}*`,
|
|
1618
1624
|
},
|
|
1619
1625
|
},
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
}
|
|
1626
|
+
},
|
|
1627
|
+
{
|
|
1628
|
+
'wildcard': {
|
|
1629
|
+
'storeId.keyword': {
|
|
1630
|
+
'value': `*${inputData.searchValue}*`,
|
|
1625
1631
|
},
|
|
1626
1632
|
},
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
}
|
|
1633
|
+
},
|
|
1634
|
+
{
|
|
1635
|
+
'wildcard': {
|
|
1636
|
+
'engagementId.keyword': {
|
|
1637
|
+
'value': `*${inputData.searchValue}*`,
|
|
1632
1638
|
},
|
|
1633
1639
|
},
|
|
1640
|
+
},
|
|
1634
1641
|
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
},
|
|
1642
|
+
{
|
|
1643
|
+
'wildcard': {
|
|
1644
|
+
'auditStatus.keyword': {
|
|
1645
|
+
'value': `*${inputData.searchValue}*`,
|
|
1640
1646
|
},
|
|
1641
1647
|
},
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
}
|
|
1648
|
+
},
|
|
1649
|
+
],
|
|
1650
|
+
'minimum_should_match': 1,
|
|
1651
|
+
};
|
|
1652
|
+
} else {
|
|
1653
|
+
search ={
|
|
1654
|
+
'must': filter,
|
|
1655
|
+
'should': [
|
|
1656
|
+
{
|
|
1657
|
+
'wildcard': {
|
|
1658
|
+
'storeName.keyword': {
|
|
1659
|
+
'value': `*${inputData.searchValue}*`,
|
|
1654
1660
|
},
|
|
1655
1661
|
},
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
}
|
|
1662
|
+
},
|
|
1663
|
+
{
|
|
1664
|
+
'wildcard': {
|
|
1665
|
+
'storeId.keyword': {
|
|
1666
|
+
'value': `*${inputData.searchValue}*`,
|
|
1661
1667
|
},
|
|
1662
1668
|
},
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
}
|
|
1669
|
+
},
|
|
1670
|
+
{
|
|
1671
|
+
'wildcard': {
|
|
1672
|
+
'engagementId.keyword': {
|
|
1673
|
+
'value': `*${inputData.searchValue}*`,
|
|
1668
1674
|
},
|
|
1669
1675
|
},
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
}
|
|
1676
|
+
},
|
|
1677
|
+
{
|
|
1678
|
+
'wildcard': {
|
|
1679
|
+
'queueId.keyword': {
|
|
1680
|
+
'value': `*${inputData.searchValue}*`,
|
|
1675
1681
|
},
|
|
1676
1682
|
},
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
}
|
|
1683
|
+
},
|
|
1684
|
+
{
|
|
1685
|
+
'wildcard': {
|
|
1686
|
+
'optumId.keyword': {
|
|
1687
|
+
'value': `*${inputData.searchValue}*`,
|
|
1682
1688
|
},
|
|
1683
1689
|
},
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
}
|
|
1690
|
+
},
|
|
1691
|
+
{
|
|
1692
|
+
'wildcard': {
|
|
1693
|
+
'visitorsType.keyword': {
|
|
1694
|
+
'value': `*${inputData.searchValue}*`,
|
|
1689
1695
|
},
|
|
1690
1696
|
},
|
|
1697
|
+
},
|
|
1691
1698
|
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
},
|
|
1699
|
+
{
|
|
1700
|
+
'wildcard': {
|
|
1701
|
+
'auditStatus.keyword': {
|
|
1702
|
+
'value': `*${inputData.searchValue}*`,
|
|
1697
1703
|
},
|
|
1698
1704
|
},
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
}
|
|
1705
|
+
},
|
|
1706
|
+
],
|
|
1707
|
+
'minimum_should_match': 1,
|
|
1708
|
+
};
|
|
1703
1709
|
}
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
let searchQuery={
|
|
1713
|
+
'from': offset,
|
|
1714
|
+
'size': limit,
|
|
1715
|
+
'query': {
|
|
1716
|
+
'bool': search,
|
|
1717
|
+
},
|
|
1718
|
+
'sort': [
|
|
1719
|
+
{ date: { order: 'desc' } },
|
|
1720
|
+
],
|
|
1721
|
+
};
|
|
1704
1722
|
|
|
1705
|
-
|
|
1723
|
+
if ( sortBy && sortBy !== '' ) {
|
|
1724
|
+
searchQuery={
|
|
1706
1725
|
'from': offset,
|
|
1707
1726
|
'size': limit,
|
|
1708
1727
|
'query': {
|
|
1709
1728
|
'bool': search,
|
|
1710
1729
|
},
|
|
1711
1730
|
'sort': [
|
|
1712
|
-
{
|
|
1731
|
+
{ [sortBy]: { order: order === -1 ?'desc':'asc' } },
|
|
1732
|
+
{ '_id': 'asc' },
|
|
1713
1733
|
],
|
|
1714
1734
|
};
|
|
1735
|
+
}
|
|
1715
1736
|
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
},
|
|
1723
|
-
'sort': [
|
|
1724
|
-
{ [sortBy]: { order: order === -1 ?'desc':'asc' } },
|
|
1725
|
-
{ '_id': 'asc' },
|
|
1726
|
-
],
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
if ( inputData.isExport==true ) {
|
|
1731
|
-
searchQuery={
|
|
1732
|
-
'from': 0,
|
|
1733
|
-
'size': 50000,
|
|
1734
|
-
'query': {
|
|
1735
|
-
'bool': search,
|
|
1736
|
-
},
|
|
1737
|
-
'sort': [
|
|
1738
|
-
{ [sortBy]: { order: order === -1 ?'desc':'asc' } },
|
|
1739
|
-
{ '_id': 'asc' },
|
|
1740
|
-
],
|
|
1741
|
-
};
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
const countQuery = {
|
|
1745
|
-
query: {
|
|
1746
|
-
bool: search,
|
|
1737
|
+
if ( inputData.isExport==true ) {
|
|
1738
|
+
searchQuery={
|
|
1739
|
+
'from': 0,
|
|
1740
|
+
'size': 50000,
|
|
1741
|
+
'query': {
|
|
1742
|
+
'bool': search,
|
|
1747
1743
|
},
|
|
1744
|
+
'sort': [
|
|
1745
|
+
{ [sortBy]: { order: order === -1 ?'desc':'asc' } },
|
|
1746
|
+
{ '_id': 'asc' },
|
|
1747
|
+
],
|
|
1748
1748
|
};
|
|
1749
|
+
}
|
|
1749
1750
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
if ( !searchValue || searchValue?.length == 0 ) {
|
|
1756
|
-
return res.sendError( 'No data found', 204 );
|
|
1757
|
-
}
|
|
1758
|
-
if ( inputData.isExport == true ) {
|
|
1759
|
-
const chunkedMappingData = await chunkArray( searchValue, 10 );
|
|
1760
|
-
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
1761
|
-
const exportData = [];
|
|
1762
|
-
for ( const element of chunk ) {
|
|
1763
|
-
const testDuration = element?._source?.testDuration;
|
|
1764
|
-
const minutes = Math.floor( testDuration / 60 );
|
|
1765
|
-
const seconds = testDuration % 60;
|
|
1766
|
-
const minutes1 =minutes> 1? `${minutes} mins` : `${minutes} min`;
|
|
1767
|
-
const seconds1 = seconds > 1? `${minutes} secs`: seconds == 1? `${minutes} sec` : '';
|
|
1768
|
-
const duration =`${minutes1} ${seconds1}`;
|
|
1769
|
-
let userName = '';
|
|
1770
|
-
if ( element?._source?.userId&&element?._source?.userId!='' ) {
|
|
1771
|
-
userName = await findOneUser( { _id: element?._source?.userId }, { _id: 0, userName: 1 } );
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
let RMName = '';
|
|
1775
|
-
let RMEmail = '';
|
|
1776
|
-
let clusterName='';
|
|
1777
|
-
if ( element?._source?.storeId&&element?._source?.storeId!='' ) {
|
|
1778
|
-
const rmListQuery =[
|
|
1779
|
-
{
|
|
1780
|
-
$match: {
|
|
1781
|
-
$and: [
|
|
1782
|
-
{
|
|
1783
|
-
clientId: { $eq: inputData?.clientId },
|
|
1784
|
-
},
|
|
1785
|
-
{
|
|
1786
|
-
configureType: { $eq: 'user' },
|
|
1787
|
-
},
|
|
1788
|
-
],
|
|
1789
|
-
},
|
|
1790
|
-
},
|
|
1791
|
-
{
|
|
1792
|
-
$unwind: {
|
|
1793
|
-
path: '$userList', preserveNullAndEmptyArrays: true,
|
|
1794
|
-
},
|
|
1795
|
-
},
|
|
1796
|
-
{
|
|
1797
|
-
$group: {
|
|
1798
|
-
_id: null,
|
|
1799
|
-
list: { $addToSet: '$userList.email' },
|
|
1800
|
-
},
|
|
1801
|
-
},
|
|
1802
|
-
{
|
|
1803
|
-
$project: {
|
|
1804
|
-
_id: 0,
|
|
1805
|
-
list: 1,
|
|
1806
|
-
},
|
|
1807
|
-
},
|
|
1808
|
-
];
|
|
1809
|
-
const getRMList = await aggregateEyeTestConfig( rmListQuery );
|
|
1810
|
-
let getCluster = [];
|
|
1811
|
-
if ( getRMList && getRMList?.length > 0 ) {
|
|
1812
|
-
const getRMQuery = [
|
|
1813
|
-
{
|
|
1814
|
-
$unwind: {
|
|
1815
|
-
path: '$Teamlead', preserveNullAndEmptyArrays: true,
|
|
1816
|
-
},
|
|
1817
|
-
},
|
|
1818
|
-
{
|
|
1819
|
-
$match: {
|
|
1820
|
-
$and: [
|
|
1821
|
-
{ 'stores.storeId': { $eq: element?._source?.storeId } },
|
|
1822
|
-
{
|
|
1823
|
-
'Teamlead.email': { $in: getRMList[0].list },
|
|
1824
|
-
},
|
|
1825
|
-
],
|
|
1826
|
-
},
|
|
1827
|
-
},
|
|
1828
|
-
{
|
|
1829
|
-
$group: {
|
|
1830
|
-
_id: null,
|
|
1831
|
-
clusterName: { $addToSet: '$clusterName' },
|
|
1832
|
-
rmList: { $addToSet: '$Teamlead.email' },
|
|
1833
|
-
},
|
|
1834
|
-
},
|
|
1835
|
-
{
|
|
1836
|
-
$project: {
|
|
1837
|
-
_id: 0,
|
|
1838
|
-
clusterName: 1,
|
|
1839
|
-
rmList: 1,
|
|
1840
|
-
},
|
|
1841
|
-
},
|
|
1842
|
-
];
|
|
1843
|
-
getCluster = await aggregateClusters( getRMQuery );
|
|
1844
|
-
}
|
|
1845
|
-
// const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
|
|
1846
|
-
RMEmail =( getCluster && getCluster?.[0]?.rmList?.length > 0 )? getCluster?.[0]?.rmList?.toString() : '';
|
|
1847
|
-
clusterName = ( getCluster && getCluster?.[0]?.clusterName?.length > 0 )? getCluster?.[0]?.clusterName?.toString() : '';
|
|
1848
|
-
if ( RMEmail && RMEmail !== '' ) {
|
|
1849
|
-
const temp = await aggregateUser( [
|
|
1850
|
-
{
|
|
1851
|
-
$match: {
|
|
1852
|
-
$and: [
|
|
1853
|
-
{
|
|
1854
|
-
email: { $in: getCluster?.[0]?.rmList },
|
|
1855
|
-
},
|
|
1856
|
-
{
|
|
1857
|
-
isActive: true,
|
|
1858
|
-
},
|
|
1859
|
-
{
|
|
1860
|
-
role: { $eq: 'admin' },
|
|
1861
|
-
},
|
|
1862
|
-
],
|
|
1863
|
-
},
|
|
1864
|
-
},
|
|
1865
|
-
{
|
|
1866
|
-
$group: {
|
|
1867
|
-
_id: null,
|
|
1868
|
-
user: { $addToSet: '$userName' },
|
|
1869
|
-
},
|
|
1870
|
-
},
|
|
1871
|
-
{
|
|
1872
|
-
$project: {
|
|
1873
|
-
_id: 0,
|
|
1874
|
-
user: 1,
|
|
1875
|
-
},
|
|
1876
|
-
},
|
|
1877
|
-
] );
|
|
1878
|
-
if ( temp && temp?.[0]?.user?.length >0 ) {
|
|
1879
|
-
RMName = temp?.[0]?.user?.toString( '' );
|
|
1880
|
-
}
|
|
1881
|
-
logger.info( { RMEmail: RMEmail } );
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
if ( element?._source?.type == 'physical' ) {
|
|
1885
|
-
exportData.push( {
|
|
1886
|
-
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1887
|
-
'Audited Date': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?dayjs( element?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA',
|
|
1888
|
-
...( req?.user?.role === 'superadmin' && { 'RM Name': RMName } ),
|
|
1889
|
-
...( req?.user?.role !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1890
|
-
'Store Name': element?._source?.storeName,
|
|
1891
|
-
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1892
|
-
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
1893
|
-
'Optom ID': element?._source?.optumId,
|
|
1894
|
-
'Queue ID': element?._source?.queueId,
|
|
1895
|
-
'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
|
|
1896
|
-
'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
|
|
1897
|
-
'Human Audited Score': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?`${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.auditedSteps/ element?._source?.totalSteps )*100 ): 0} %`:'NA',
|
|
1898
|
-
'Steps Covered By Human': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?element?._source?.auditedSteps :'NA',
|
|
1899
|
-
'Trust Score': element?._source?.trustScore == null || element?._source?.trustScore ==undefined ? 'NA' : `${element?._source?.trustScore} %`,
|
|
1900
|
-
'Visitor Type': element?._source?.visitorsType,
|
|
1901
|
-
'Test Duration': duration || '',
|
|
1902
|
-
'Eye Test Status': element?._source?.comment == 'Possible Fake Video' ? 'Fake':'Genuine',
|
|
1903
|
-
'Comments ': element._source?.subComment || '',
|
|
1904
|
-
'Audit Status': element?._source?.auditStatus || '',
|
|
1905
|
-
'Audited By': userName?.userName || '',
|
|
1906
|
-
|
|
1907
|
-
} );
|
|
1908
|
-
} else {
|
|
1909
|
-
exportData.push( {
|
|
1910
|
-
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1911
|
-
'Audited Date': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?dayjs( element?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA',
|
|
1912
|
-
...( req?.user?.role === 'superadmin' && { 'RM Name': RMName } ),
|
|
1913
|
-
...( req?.user?.role !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1914
|
-
'Store Name': element?._source?.storeName,
|
|
1915
|
-
'Store Name': element?._source?.storeName,
|
|
1916
|
-
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1917
|
-
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
1918
|
-
'Engagement ID': element?._source?.engagementId,
|
|
1919
|
-
'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
|
|
1920
|
-
'Human Audited Score': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?`${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.auditedSteps/ element?._source?.totalSteps )*100 ): 0} %`:'NA',
|
|
1921
|
-
'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
|
|
1922
|
-
'Steps Covered By Human': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?element?._source?.auditedSteps :'NA',
|
|
1923
|
-
'Trust Score': element?._source?.trustScore == null || element?._source?.trustScore ==undefined ? 'NA' : `${element?._source?.trustScore} %`,
|
|
1924
|
-
'Test Duration': duration || '',
|
|
1925
|
-
'Audit Status': element?._source?.auditStatus || '',
|
|
1926
|
-
'Audited By': userName?.userName || '',
|
|
1751
|
+
const countQuery = {
|
|
1752
|
+
query: {
|
|
1753
|
+
bool: search,
|
|
1754
|
+
},
|
|
1755
|
+
};
|
|
1927
1756
|
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1757
|
+
const result = await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
|
|
1758
|
+
const getCount = inputData.isExport==true? null:await getOpenSearchCount( openSearch.EyeTestInput, countQuery );
|
|
1759
|
+
const count =inputData.isExport==true?null: getCount?.body?.count;
|
|
1760
|
+
const searchValue = result?.body?.hits?.hits;
|
|
1761
|
+
const temp =[];
|
|
1762
|
+
if ( !searchValue || searchValue?.length == 0 ) {
|
|
1763
|
+
return res.sendError( 'No data found', 204 );
|
|
1764
|
+
}
|
|
1765
|
+
if ( inputData.isExport == true ) {
|
|
1766
|
+
const chunkedMappingData = await chunkArray( searchValue, 10 );
|
|
1767
|
+
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
1768
|
+
const exportData = [];
|
|
1769
|
+
for ( const element of chunk ) {
|
|
1770
|
+
const testDuration = element?._source?.testDuration;
|
|
1771
|
+
const minutes = Math.floor( testDuration / 60 );
|
|
1772
|
+
const seconds = testDuration % 60;
|
|
1773
|
+
const minutes1 =minutes> 1? `${minutes} mins` : `${minutes} min`;
|
|
1774
|
+
const seconds1 = seconds > 1? `${minutes} secs`: seconds == 1? `${minutes} sec` : '';
|
|
1775
|
+
const duration =`${minutes1} ${seconds1}`;
|
|
1776
|
+
let userName = '';
|
|
1777
|
+
if ( element?._source?.userId&&element?._source?.userId!='' ) {
|
|
1778
|
+
userName = await findOneUser( { _id: element?._source?.userId }, { _id: 0, userName: 1 } );
|
|
1944
1779
|
}
|
|
1780
|
+
|
|
1945
1781
|
let RMName = '';
|
|
1946
1782
|
let RMEmail = '';
|
|
1947
1783
|
let clusterName='';
|
|
1948
|
-
if (
|
|
1784
|
+
if ( element?._source?.storeId&&element?._source?.storeId!='' ) {
|
|
1949
1785
|
const rmListQuery =[
|
|
1950
1786
|
{
|
|
1951
1787
|
$match: {
|
|
@@ -1989,7 +1825,7 @@ export async function summaryList( req, res ) {
|
|
|
1989
1825
|
{
|
|
1990
1826
|
$match: {
|
|
1991
1827
|
$and: [
|
|
1992
|
-
{ 'stores.storeId': { $eq:
|
|
1828
|
+
{ 'stores.storeId': { $eq: element?._source?.storeId } },
|
|
1993
1829
|
{
|
|
1994
1830
|
'Teamlead.email': { $in: getRMList[0].list },
|
|
1995
1831
|
},
|
|
@@ -2016,14 +1852,13 @@ export async function summaryList( req, res ) {
|
|
|
2016
1852
|
// const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
|
|
2017
1853
|
RMEmail =( getCluster && getCluster?.[0]?.rmList?.length > 0 )? getCluster?.[0]?.rmList?.toString() : '';
|
|
2018
1854
|
clusterName = ( getCluster && getCluster?.[0]?.clusterName?.length > 0 )? getCluster?.[0]?.clusterName?.toString() : '';
|
|
2019
|
-
|
|
2020
1855
|
if ( RMEmail && RMEmail !== '' ) {
|
|
2021
1856
|
const temp = await aggregateUser( [
|
|
2022
1857
|
{
|
|
2023
1858
|
$match: {
|
|
2024
1859
|
$and: [
|
|
2025
1860
|
{
|
|
2026
|
-
email: { $in: getCluster[0]?.rmList },
|
|
1861
|
+
email: { $in: getCluster?.[0]?.rmList },
|
|
2027
1862
|
},
|
|
2028
1863
|
{
|
|
2029
1864
|
isActive: true,
|
|
@@ -2050,30 +1885,200 @@ export async function summaryList( req, res ) {
|
|
|
2050
1885
|
if ( temp && temp?.[0]?.user?.length >0 ) {
|
|
2051
1886
|
RMName = temp?.[0]?.user?.toString( '' );
|
|
2052
1887
|
}
|
|
1888
|
+
logger.info( { RMEmail: RMEmail } );
|
|
2053
1889
|
}
|
|
2054
1890
|
}
|
|
1891
|
+
if ( element?._source?.type == 'physical' ) {
|
|
1892
|
+
exportData.push( {
|
|
1893
|
+
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1894
|
+
'Audited Date': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?dayjs( element?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA',
|
|
1895
|
+
...( req?.user?.role === 'superadmin' && { 'RM Name': RMName } ),
|
|
1896
|
+
...( req?.user?.role !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1897
|
+
'Store Name': element?._source?.storeName,
|
|
1898
|
+
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1899
|
+
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
1900
|
+
'Optom ID': element?._source?.optumId,
|
|
1901
|
+
'Queue ID': element?._source?.queueId,
|
|
1902
|
+
'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
|
|
1903
|
+
'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
|
|
1904
|
+
'Human Audited Score': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?`${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.auditedSteps/ element?._source?.totalSteps )*100 ): 0} %`:'NA',
|
|
1905
|
+
'Steps Covered By Human': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?element?._source?.auditedSteps :'NA',
|
|
1906
|
+
'Trust Score': element?._source?.trustScore == null || element?._source?.trustScore ==undefined ? 'NA' : `${element?._source?.trustScore} %`,
|
|
1907
|
+
'Visitor Type': element?._source?.visitorsType,
|
|
1908
|
+
'Test Duration': duration || '',
|
|
1909
|
+
'Eye Test Status': element?._source?.comment == 'Possible Fake Video' ? 'Fake':'Genuine',
|
|
1910
|
+
'Comments ': element._source?.subComment || '',
|
|
1911
|
+
'Audit Status': element?._source?.auditStatus || '',
|
|
1912
|
+
'Audited By': userName?.userName || '',
|
|
2055
1913
|
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
1914
|
+
} );
|
|
1915
|
+
} else {
|
|
1916
|
+
exportData.push( {
|
|
1917
|
+
'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
|
|
1918
|
+
'Audited Date': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?dayjs( element?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA',
|
|
1919
|
+
...( req?.user?.role === 'superadmin' && { 'RM Name': RMName } ),
|
|
1920
|
+
...( req?.user?.role !== 'user' && { 'Cluster Name': clusterName } ),
|
|
1921
|
+
'Store Name': element?._source?.storeName,
|
|
1922
|
+
'Store Name': element?._source?.storeName,
|
|
1923
|
+
'Store ID': element?._source?.storeId || 'Un Assigned',
|
|
1924
|
+
'Store Name': element?._source?.storeName ||'Un Assigned',
|
|
1925
|
+
'Engagement ID': element?._source?.engagementId,
|
|
1926
|
+
'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
|
|
1927
|
+
'Human Audited Score': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?`${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.auditedSteps/ element?._source?.totalSteps )*100 ): 0} %`:'NA',
|
|
1928
|
+
'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
|
|
1929
|
+
'Steps Covered By Human': [ 'Re-Audited', 'Audited' ].includes( element?._source?.auditStatus )?element?._source?.auditedSteps :'NA',
|
|
1930
|
+
'Trust Score': element?._source?.trustScore == null || element?._source?.trustScore ==undefined ? 'NA' : `${element?._source?.trustScore} %`,
|
|
1931
|
+
'Test Duration': duration || '',
|
|
1932
|
+
'Audit Status': element?._source?.auditStatus || '',
|
|
1933
|
+
'Audited By': userName?.userName || '',
|
|
1934
|
+
|
|
1935
|
+
} );
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
return exportData;
|
|
1939
|
+
} );
|
|
1940
|
+
const mappedArrays = await Promise.all( promises );
|
|
1941
|
+
const result = mappedArrays.flat();
|
|
1942
|
+
await download( result, res );
|
|
1943
|
+
return;
|
|
1944
|
+
} else {
|
|
1945
|
+
for ( const [ i, item ] of searchValue.entries() ) {
|
|
1946
|
+
temp.push( item?._source );
|
|
1947
|
+
let userName='';
|
|
1948
|
+
if ( item?._source?.userId&&item?._source?.userId!='' ) {
|
|
1949
|
+
userName = await findOneUser( { _id: item?._source?.userId }, { _id: 0, userName: 1 } );
|
|
1950
|
+
}
|
|
1951
|
+
let RMName = '';
|
|
1952
|
+
let RMEmail = '';
|
|
1953
|
+
let clusterName='';
|
|
1954
|
+
if ( item?._source?.storeId&&item?._source?.storeId!='' ) {
|
|
1955
|
+
const rmListQuery =[
|
|
1956
|
+
{
|
|
1957
|
+
$match: {
|
|
1958
|
+
$and: [
|
|
1959
|
+
{
|
|
1960
|
+
clientId: { $eq: inputData?.clientId },
|
|
1961
|
+
},
|
|
1962
|
+
{
|
|
1963
|
+
configureType: { $eq: 'user' },
|
|
1964
|
+
},
|
|
1965
|
+
],
|
|
1966
|
+
},
|
|
1967
|
+
},
|
|
1968
|
+
{
|
|
1969
|
+
$unwind: {
|
|
1970
|
+
path: '$userList', preserveNullAndEmptyArrays: true,
|
|
1971
|
+
},
|
|
1972
|
+
},
|
|
1973
|
+
{
|
|
1974
|
+
$group: {
|
|
1975
|
+
_id: null,
|
|
1976
|
+
list: { $addToSet: '$userList.email' },
|
|
1977
|
+
},
|
|
1978
|
+
},
|
|
1979
|
+
{
|
|
1980
|
+
$project: {
|
|
1981
|
+
_id: 0,
|
|
1982
|
+
list: 1,
|
|
1983
|
+
},
|
|
1984
|
+
},
|
|
1985
|
+
];
|
|
1986
|
+
const getRMList = await aggregateEyeTestConfig( rmListQuery );
|
|
1987
|
+
let getCluster = [];
|
|
1988
|
+
if ( getRMList && getRMList?.length > 0 ) {
|
|
1989
|
+
const getRMQuery = [
|
|
1990
|
+
{
|
|
1991
|
+
$unwind: {
|
|
1992
|
+
path: '$Teamlead', preserveNullAndEmptyArrays: true,
|
|
1993
|
+
},
|
|
1994
|
+
},
|
|
1995
|
+
{
|
|
1996
|
+
$match: {
|
|
1997
|
+
$and: [
|
|
1998
|
+
{ 'stores.storeId': { $eq: item?._source?.storeId } },
|
|
1999
|
+
{
|
|
2000
|
+
'Teamlead.email': { $in: getRMList[0].list },
|
|
2001
|
+
},
|
|
2002
|
+
],
|
|
2003
|
+
},
|
|
2004
|
+
},
|
|
2005
|
+
{
|
|
2006
|
+
$group: {
|
|
2007
|
+
_id: null,
|
|
2008
|
+
clusterName: { $addToSet: '$clusterName' },
|
|
2009
|
+
rmList: { $addToSet: '$Teamlead.email' },
|
|
2010
|
+
},
|
|
2011
|
+
},
|
|
2012
|
+
{
|
|
2013
|
+
$project: {
|
|
2014
|
+
_id: 0,
|
|
2015
|
+
clusterName: 1,
|
|
2016
|
+
rmList: 1,
|
|
2017
|
+
},
|
|
2018
|
+
},
|
|
2019
|
+
];
|
|
2020
|
+
getCluster = await aggregateClusters( getRMQuery );
|
|
2021
|
+
}
|
|
2022
|
+
// const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
|
|
2023
|
+
RMEmail =( getCluster && getCluster?.[0]?.rmList?.length > 0 )? getCluster?.[0]?.rmList?.toString() : '';
|
|
2024
|
+
clusterName = ( getCluster && getCluster?.[0]?.clusterName?.length > 0 )? getCluster?.[0]?.clusterName?.toString() : '';
|
|
2025
|
+
|
|
2026
|
+
if ( RMEmail && RMEmail !== '' ) {
|
|
2027
|
+
const temp = await aggregateUser( [
|
|
2028
|
+
{
|
|
2029
|
+
$match: {
|
|
2030
|
+
$and: [
|
|
2031
|
+
{
|
|
2032
|
+
email: { $in: getCluster[0]?.rmList },
|
|
2033
|
+
},
|
|
2034
|
+
{
|
|
2035
|
+
isActive: true,
|
|
2036
|
+
},
|
|
2037
|
+
{
|
|
2038
|
+
role: { $eq: 'admin' },
|
|
2039
|
+
},
|
|
2040
|
+
],
|
|
2041
|
+
},
|
|
2042
|
+
},
|
|
2043
|
+
{
|
|
2044
|
+
$group: {
|
|
2045
|
+
_id: null,
|
|
2046
|
+
user: { $addToSet: '$userName' },
|
|
2047
|
+
},
|
|
2048
|
+
},
|
|
2049
|
+
{
|
|
2050
|
+
$project: {
|
|
2051
|
+
_id: 0,
|
|
2052
|
+
user: 1,
|
|
2053
|
+
},
|
|
2054
|
+
},
|
|
2055
|
+
] );
|
|
2056
|
+
if ( temp && temp?.[0]?.user?.length >0 ) {
|
|
2057
|
+
RMName = temp?.[0]?.user?.toString( '' );
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2072
2060
|
}
|
|
2073
|
-
}
|
|
2074
2061
|
|
|
2075
|
-
|
|
2062
|
+
const testDuration = item?._source?.testDuration;
|
|
2063
|
+
const minutes = Math.floor( testDuration / 60 );
|
|
2064
|
+
const seconds = testDuration % 60;
|
|
2065
|
+
temp[i].complianceScore = `${item?._source?.totalSteps>0 ? Math.round( ( item?._source?.coveredStepsAI/ item?._source?.totalSteps )*100 ): 0} %`;
|
|
2066
|
+
temp[i].humanComplianceScore = [ 'Re-Audited', 'Audited' ].includes( item?._source?.auditStatus )?`${item?._source?.totalSteps>0 ? Math.round( ( item?._source?.auditedSteps/ item?._source?.totalSteps )*100 ): 0} %`:'NA';
|
|
2067
|
+
temp[i].min = minutes;
|
|
2068
|
+
temp[i].sec = seconds;
|
|
2069
|
+
temp[i].auditedBy = userName?.userName || '';
|
|
2070
|
+
temp[i].date = dayjs( item?._source?.date ).format( 'D MMM, YYYY' );
|
|
2071
|
+
temp[i].auditedDate = [ 'Re-Audited', 'Audited' ].includes( item?._source?.auditStatus )?dayjs( item?._source?.updatedAt ).format( 'D MMM, YYYY' ): 'NA';
|
|
2072
|
+
temp[i].RMName = RMName;
|
|
2073
|
+
temp[i].clusterName =clusterName;
|
|
2074
|
+
temp[i].RMEmail =RMEmail;
|
|
2075
|
+
const trustScore = temp[i].trustScore;
|
|
2076
|
+
temp[i].trustScore = ( trustScore == null || trustScore == undefined ) ? 'NA' :`${trustScore + ' %'}`;
|
|
2077
|
+
temp[i]._id = item?._id;
|
|
2078
|
+
}
|
|
2076
2079
|
}
|
|
2080
|
+
|
|
2081
|
+
return res.sendSuccess( { result: temp, count: count } );
|
|
2077
2082
|
} catch ( error ) {
|
|
2078
2083
|
const err = error.message || 'Internal Server Error';
|
|
2079
2084
|
logger.error( { message: error, data: req.body, function: 'eyetestAudit-controller-summaryList' } );
|
|
@@ -2085,7 +2090,7 @@ export async function summaryCard( req, res ) {
|
|
|
2085
2090
|
try {
|
|
2086
2091
|
const inputData = req.body;
|
|
2087
2092
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2088
|
-
|
|
2093
|
+
|
|
2089
2094
|
let filter =[
|
|
2090
2095
|
{
|
|
2091
2096
|
'range': {
|
|
@@ -2354,7 +2359,7 @@ export async function summaryCard( req, res ) {
|
|
|
2354
2359
|
initialValue.completedFiles =temp?.completedFiles?.doc_count;
|
|
2355
2360
|
initialValue.completedRatio =Math.round( temp?.completedRatio?.value || 0 );
|
|
2356
2361
|
initialValue.tangoScore =Math.round( temp?.tangoScore?.value || 0 )+ ' %';
|
|
2357
|
-
initialValue.humanScore =Math.round( temp?.humanScore?.value || 0 )+ ' %';
|
|
2362
|
+
initialValue.humanScore =Math.round( temp?.humanScore?.scoreValue?.value || 0 )+ ' %';
|
|
2358
2363
|
initialValue.tangoScoreTrend =temp?.tangoScoreTrend?.value || 0;
|
|
2359
2364
|
initialValue.trustScore =temp?.trustScore?.avg_val?.value == null || temp?.trustScore?.avg_val?.value === undefined ? 'NA':Math.round( temp?.trustScore?.avg_val?.value );
|
|
2360
2365
|
initialValue.trend = initialValue.tangoScoreTrend < 0? false : true;
|