tango-app-api-audit 3.5.6 → 3.5.7-stage.0
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 +121 -135
package/package.json
CHANGED
|
@@ -537,11 +537,10 @@ export async function getAuditFile( req, res ) {
|
|
|
537
537
|
fetchData.ContinuationToken = decodeURIComponent( inputData.nextId );
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
|
-
|
|
541
|
-
const getQuery = msg.audit_type =='Audit'?
|
|
540
|
+
const getQuery = msg.audit_type =='ReAudit'?
|
|
542
541
|
{
|
|
543
542
|
size: inputData?.limit || 2,
|
|
544
|
-
_source: [ 'module', 'status', 'date', 'store_id', 'personPath', 'REIDCluster', '
|
|
543
|
+
_source: [ 'module', 'status', 'date', 'store_id', 'outputCluster', 'personPath', 'REIDCluster', 'isEmployee', 'isJunk', 'EmployeeStatusFinal' ], // Only fetch necessary fields
|
|
545
544
|
|
|
546
545
|
query: {
|
|
547
546
|
bool: {
|
|
@@ -559,21 +558,21 @@ export async function getAuditFile( req, res ) {
|
|
|
559
558
|
term: { 'status.keyword': 'PP_CLUSTER_FORMED' },
|
|
560
559
|
},
|
|
561
560
|
{
|
|
562
|
-
terms: {
|
|
561
|
+
terms: { EmployeeStatusFinal: [ 1, 2 ] },
|
|
563
562
|
},
|
|
564
563
|
],
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
564
|
+
'should': [
|
|
565
|
+
{ 'term': { 'isJunk': false } },
|
|
566
|
+
{ 'bool': { 'must_not': { 'exists': { 'field': 'isJunk' } } } },
|
|
567
|
+
],
|
|
568
|
+
'minimum_should_match': 1,
|
|
570
569
|
},
|
|
571
570
|
},
|
|
572
571
|
|
|
573
572
|
}:
|
|
574
573
|
{
|
|
575
574
|
size: inputData?.limit || 2,
|
|
576
|
-
_source: [ 'module', 'status', 'date', 'store_id', '
|
|
575
|
+
_source: [ 'module', 'status', 'date', 'store_id', 'personPath', 'REIDCluster', 'EmployeeStatusProposed', 'isJunk', 'EmployeeStatusFinal' ], // Only fetch necessary fields
|
|
577
576
|
|
|
578
577
|
query: {
|
|
579
578
|
bool: {
|
|
@@ -591,14 +590,9 @@ export async function getAuditFile( req, res ) {
|
|
|
591
590
|
term: { 'status.keyword': 'PP_CLUSTER_FORMED' },
|
|
592
591
|
},
|
|
593
592
|
{
|
|
594
|
-
terms: {
|
|
593
|
+
terms: { EmployeeStatusProposed: [ 1, 2 ] },
|
|
595
594
|
},
|
|
596
595
|
],
|
|
597
|
-
'should': [
|
|
598
|
-
{ 'term': { 'isJunk': false } },
|
|
599
|
-
{ 'bool': { 'must_not': { 'exists': { 'field': 'isJunk' } } } },
|
|
600
|
-
],
|
|
601
|
-
'minimum_should_match': 1,
|
|
602
596
|
},
|
|
603
597
|
},
|
|
604
598
|
|
|
@@ -615,7 +609,7 @@ export async function getAuditFile( req, res ) {
|
|
|
615
609
|
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
616
610
|
const img =msg.zone_id === 'track' ?folderPath[i]?._source?.personPath?.split( '/' ): folderPath[i].Key.split( '/' );
|
|
617
611
|
const image = img[3]?.split( '.' );
|
|
618
|
-
const indexes = msg.zone_id === 'track' ? folderPath[i]?._source?.outputCluster
|
|
612
|
+
const indexes = msg.zone_id === 'track' ? msg.audit_type === 'ReAudit'? folderPath[i]?._source?.outputCluster ===50000? folderPath[i]?._source?.REIDCluster:folderPath[i]?._source?.outputCluster:folderPath[i]?._source?.REIDCluster: image[0]?.split( '_' );
|
|
619
613
|
fetchData.file_path = msg.zone_id === 'track' ?folderPath[i]?._source?.personPath:folderPath[i].Key;
|
|
620
614
|
const data =msg.zone_id === 'track' ? `${url.trackInput}${folderPath[i]?._source?.personPath}` :await signedUrl( fetchData );
|
|
621
615
|
const mapimg = {
|
|
@@ -1452,7 +1446,7 @@ export async function save( req, res ) {
|
|
|
1452
1446
|
// Junk Mapping
|
|
1453
1447
|
let junkCount = [];
|
|
1454
1448
|
let empCount = [];
|
|
1455
|
-
|
|
1449
|
+
let customerCount = [];
|
|
1456
1450
|
if ( inputData.junkCount >0 ) {
|
|
1457
1451
|
const chunkedJunkMappingData = await filteredMap( inputData.junk );
|
|
1458
1452
|
junkCount = chunkedJunkMappingData;
|
|
@@ -1466,86 +1460,79 @@ export async function save( req, res ) {
|
|
|
1466
1460
|
{
|
|
1467
1461
|
term: { 'module.keyword': 'CUSTOMER' },
|
|
1468
1462
|
},
|
|
1463
|
+
{
|
|
1464
|
+
terms: { REIDCluster: chunkedJunkMappingData },
|
|
1465
|
+
},
|
|
1469
1466
|
];
|
|
1470
|
-
inputData.auditType == 'Audit'? filter.push(
|
|
1471
|
-
{
|
|
1472
|
-
terms: { REIDCluster: chunkedJunkMappingData },
|
|
1473
|
-
},
|
|
1474
|
-
):
|
|
1475
|
-
filter.push(
|
|
1476
|
-
{
|
|
1477
|
-
terms: { outputCluster: chunkedJunkMappingData },
|
|
1478
|
-
},
|
|
1479
|
-
);
|
|
1480
|
-
logger.info( { chunkedJunkMappingData: chunkedJunkMappingData } );
|
|
1481
|
-
const getQuery = {
|
|
1482
|
-
size: 10000,
|
|
1483
|
-
_source: false, // do not fetch full source
|
|
1484
|
-
stored_fields: [], // exclude all stored fields
|
|
1485
|
-
query: {
|
|
1486
|
-
bool: {
|
|
1487
|
-
must: filter,
|
|
1488
|
-
},
|
|
1489
|
-
},
|
|
1490
1467
|
|
|
1491
|
-
};
|
|
1492
|
-
const
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1468
|
+
logger.info( { chunkedJunkMappingData: chunkedJunkMappingData } );
|
|
1469
|
+
const getQuery = {
|
|
1470
|
+
size: 10000,
|
|
1471
|
+
_source: false, // do not fetch full source
|
|
1472
|
+
stored_fields: [], // exclude all stored fields
|
|
1473
|
+
query: {
|
|
1474
|
+
bool: {
|
|
1475
|
+
must: filter,
|
|
1476
|
+
},
|
|
1477
|
+
},
|
|
1478
|
+
|
|
1479
|
+
};
|
|
1480
|
+
const getId = await getOpenSearchData( openSearch.trackerInput, getQuery );
|
|
1481
|
+
const ids = getId?.body?.hits?.total?.value || null;
|
|
1482
|
+
if ( ids ) {
|
|
1483
|
+
const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
|
|
1484
|
+
const updatedField = { isJunk: true }; // your field updates
|
|
1485
|
+
const body = temp.flatMap( ( id ) => [
|
|
1486
|
+
{ update: { _index: openSearch.trackerInput, _id: id } },
|
|
1487
|
+
{ doc: updatedField },
|
|
1488
|
+
] );
|
|
1489
|
+
const re= await bulkUpdate( body );
|
|
1490
|
+
logger.info( { getId: getId, re: re, storeId: inputData.storeId, fileDate: inputData.fileDate, function: 'tracking save - junk' } );
|
|
1491
|
+
}
|
|
1504
1492
|
}
|
|
1505
1493
|
|
|
1506
1494
|
|
|
1507
1495
|
// Employee Mapping
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
},
|
|
1496
|
+
|
|
1497
|
+
if ( inputData.employeeCount >0 ) {
|
|
1498
|
+
const chunkedEmpMappingData = await filteredMap( inputData.employee );
|
|
1499
|
+
empCount = chunkedEmpMappingData;
|
|
1500
|
+
const getQuery = {
|
|
1501
|
+
size: 10000,
|
|
1502
|
+
_source: false, // do not fetch full source
|
|
1503
|
+
stored_fields: [], // exclude all stored fields
|
|
1504
|
+
query: {
|
|
1505
|
+
bool: {
|
|
1506
|
+
must: [
|
|
1507
|
+
{
|
|
1508
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
1509
|
+
},
|
|
1510
|
+
{
|
|
1511
|
+
terms: { REIDCluster: chunkedEmpMappingData },
|
|
1512
|
+
},
|
|
1513
|
+
{
|
|
1514
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
1515
|
+
},
|
|
1516
|
+
{
|
|
1517
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
1518
|
+
},
|
|
1519
|
+
],
|
|
1533
1520
|
},
|
|
1521
|
+
},
|
|
1534
1522
|
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
}
|
|
1523
|
+
};
|
|
1524
|
+
const getId = await getOpenSearchData( openSearch.trackerInput, getQuery );
|
|
1525
|
+
const ids = getId?.body?.hits?.total?.value || null;
|
|
1526
|
+
if ( ids ) {
|
|
1527
|
+
const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
|
|
1528
|
+
|
|
1529
|
+
const updatedField = { EmployeeStatusFinal: 0 }; // your field updates
|
|
1530
|
+
const body = temp.flatMap( ( id ) => [
|
|
1531
|
+
{ update: { _index: openSearch.trackerInput, _id: id } },
|
|
1532
|
+
{ doc: updatedField },
|
|
1533
|
+
] );
|
|
1534
|
+
const re= await bulkUpdate( body );
|
|
1535
|
+
logger.info( { getId: getId, re: re, storeId: inputData.storeId, fileDate: inputData.fileDate, function: 'tracking save - Employee' } );
|
|
1549
1536
|
}
|
|
1550
1537
|
}
|
|
1551
1538
|
|
|
@@ -1558,7 +1545,7 @@ if ( ids ) {
|
|
|
1558
1545
|
chunk.map( async ( item ) => {
|
|
1559
1546
|
const imgName= item.img_name;
|
|
1560
1547
|
const mappedId= item.mappedid.map( ( m ) => m.img_name );
|
|
1561
|
-
|
|
1548
|
+
customerCount.push( ...mappedId );
|
|
1562
1549
|
const searchQuery = {
|
|
1563
1550
|
size: 10000,
|
|
1564
1551
|
_source: false, // do not fetch full source
|
|
@@ -1570,7 +1557,7 @@ if ( ids ) {
|
|
|
1570
1557
|
term: { 'store_id.keyword': inputData.storeId },
|
|
1571
1558
|
},
|
|
1572
1559
|
{
|
|
1573
|
-
terms: {
|
|
1560
|
+
terms: { REIDCluster: mappedId },
|
|
1574
1561
|
},
|
|
1575
1562
|
{
|
|
1576
1563
|
term: { 'date.keyword': inputData.fileDate },
|
|
@@ -1597,7 +1584,7 @@ if ( ids ) {
|
|
|
1597
1584
|
} );
|
|
1598
1585
|
}
|
|
1599
1586
|
|
|
1600
|
-
if ( inputData.auditType
|
|
1587
|
+
if ( inputData.auditType !== 'ReAudit' ) {
|
|
1601
1588
|
// junk Mapping
|
|
1602
1589
|
const getJunkQuery = {
|
|
1603
1590
|
size: 10000,
|
|
@@ -1663,7 +1650,7 @@ if ( ids ) {
|
|
|
1663
1650
|
term: { 'module.keyword': 'CUSTOMER' },
|
|
1664
1651
|
},
|
|
1665
1652
|
{
|
|
1666
|
-
|
|
1653
|
+
terms: { EmployeeStatusProposed: [ 1, 2 ] },
|
|
1667
1654
|
},
|
|
1668
1655
|
],
|
|
1669
1656
|
},
|
|
@@ -1685,46 +1672,45 @@ if ( ids ) {
|
|
|
1685
1672
|
}
|
|
1686
1673
|
|
|
1687
1674
|
// customer Mapping
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
// }
|
|
1675
|
+
const getCusQuery = {
|
|
1676
|
+
size: 10000,
|
|
1677
|
+
_source: false, // do not fetch full source
|
|
1678
|
+
stored_fields: [], // exclude all stored fields
|
|
1679
|
+
query: {
|
|
1680
|
+
bool: {
|
|
1681
|
+
must_not: {
|
|
1682
|
+
terms: {
|
|
1683
|
+
outputCluster: customerCount, // how can i c=handle if incase empCount === []
|
|
1684
|
+
},
|
|
1685
|
+
},
|
|
1686
|
+
must: [
|
|
1687
|
+
{
|
|
1688
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
1689
|
+
},
|
|
1690
|
+
{
|
|
1691
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
1692
|
+
},
|
|
1693
|
+
{
|
|
1694
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
1695
|
+
},
|
|
1696
|
+
],
|
|
1697
|
+
},
|
|
1698
|
+
},
|
|
1699
|
+
|
|
1700
|
+
};
|
|
1701
|
+
|
|
1702
|
+
const getCusId = await getOpenSearchData( openSearch.trackerInput, getCusQuery );
|
|
1703
|
+
const cusIds = getCusId?.body?.hits?.total?.value || null;
|
|
1704
|
+
if ( cusIds ) {
|
|
1705
|
+
const temp = getCusId?.body?.hits?.hits.map( ( item ) => item._id );
|
|
1706
|
+
logger.info( { custoemrTemp: temp } );
|
|
1707
|
+
const body = temp.flatMap( ( id ) => [
|
|
1708
|
+
{ update: { _index: openSearch.trackerInput, _id: id } },
|
|
1709
|
+
{ doc: { outputCluster: 50000 } },
|
|
1710
|
+
] );
|
|
1711
|
+
const re= await bulkUpdate( body );
|
|
1712
|
+
logger.info( { getCusId: getCusId, re: re, storeId: inputData.storeId, auditType: inputData.auditType, fileDate: inputData.fileDate, function: 'tracking save - junk false mapping' } );
|
|
1713
|
+
}
|
|
1728
1714
|
}
|
|
1729
1715
|
}
|
|
1730
1716
|
|
|
@@ -1768,7 +1754,7 @@ if ( ids ) {
|
|
|
1768
1754
|
const ratio = ( ( storeAuditData.beforeCount - inputData.customerCount ) / storeAuditData.beforeCount );
|
|
1769
1755
|
if ( ratio < clientData[0].auditConfigs.ratio &&
|
|
1770
1756
|
inputData.auditType == 'Audit' &&
|
|
1771
|
-
inputData.moduleType == '
|
|
1757
|
+
inputData.moduleType == 'traffic1'
|
|
1772
1758
|
) {
|
|
1773
1759
|
logger.info(
|
|
1774
1760
|
`Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
|