tango-app-api-audit 3.5.6 → 3.5.7-stage.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.5.6",
3
+ "version": "3.5.7-stage.1",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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', 'EmployeeStatusProposed', 'isJunk', 'EmployeeStatusFinal' ], // Only fetch necessary fields
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: { EmployeeStatusProposed: [ 1, 2 ] },
561
+ terms: { EmployeeStatusFinal: [ 1, 2 ] },
563
562
  },
564
563
  ],
565
- // 'should': [
566
- // { 'term': { 'isJunk': false } },
567
- // { 'bool': { 'must_not': { 'exists': { 'field': 'isJunk' } } } },
568
- // ],
569
- // 'minimum_should_match': 1,
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', 'outputCluster', 'personPath', 'isEmployee', 'isJunk', 'EmployeeStatusFinal' ], // Only fetch necessary fields
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: { EmployeeStatusFinal: [ 1, 2 ] },
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 || folderPath[i]?._source?.REIDCluster : image[0]?.split( '_' );
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 = {
@@ -1403,12 +1397,13 @@ export async function save( req, res ) {
1403
1397
  params.Bucket = bucket.auditUploadBucket;
1404
1398
  } else {
1405
1399
  params.Bucket = bucket.masterJson;
1400
+ params.Key = `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.srcMasterJsonFile}`
1406
1401
  }
1407
1402
  const fileData = await getJsonFileData( params );
1408
1403
 
1409
1404
  if ( fileData?.statusCode ) {
1410
1405
  logger.error( {
1411
- error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
1406
+ error: `ERROR IN UPLOAD PATH: ${params.Key}`,
1412
1407
  type: 'UPLOAD_ERROR',
1413
1408
  } );
1414
1409
  return res.sendError( fileData, 500 );
@@ -1452,7 +1447,7 @@ export async function save( req, res ) {
1452
1447
  // Junk Mapping
1453
1448
  let junkCount = [];
1454
1449
  let empCount = [];
1455
- // let customerCount = [];
1450
+ let customerCount = [];
1456
1451
  if ( inputData.junkCount >0 ) {
1457
1452
  const chunkedJunkMappingData = await filteredMap( inputData.junk );
1458
1453
  junkCount = chunkedJunkMappingData;
@@ -1466,86 +1461,79 @@ export async function save( req, res ) {
1466
1461
  {
1467
1462
  term: { 'module.keyword': 'CUSTOMER' },
1468
1463
  },
1464
+ {
1465
+ terms: { REIDCluster: chunkedJunkMappingData },
1466
+ },
1469
1467
  ];
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
1468
 
1491
- };
1492
- const getId = await getOpenSearchData( openSearch.trackerInput, getQuery );
1493
- const ids = getId?.body?.hits?.total?.value || null;
1494
- if ( ids ) {
1495
- const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
1496
- const updatedField = { isJunk: true }; // your field updates
1497
- const body = temp.flatMap( ( id ) => [
1498
- { update: { _index: openSearch.trackerInput, _id: id } },
1499
- { doc: updatedField },
1500
- ] );
1501
- const re= await bulkUpdate( body );
1502
- logger.info( { getId: getId, re: re, storeId: inputData.storeId, fileDate: inputData.fileDate, function: 'tracking save - junk' } );
1503
- }
1469
+ logger.info( { chunkedJunkMappingData: chunkedJunkMappingData } );
1470
+ const getQuery = {
1471
+ size: 10000,
1472
+ _source: false, // do not fetch full source
1473
+ stored_fields: [], // exclude all stored fields
1474
+ query: {
1475
+ bool: {
1476
+ must: filter,
1477
+ },
1478
+ },
1479
+
1480
+ };
1481
+ const getId = await getOpenSearchData( openSearch.trackerInput, getQuery );
1482
+ const ids = getId?.body?.hits?.total?.value || null;
1483
+ if ( ids ) {
1484
+ const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
1485
+ const updatedField = { isJunk: true }; // your field updates
1486
+ const body = temp.flatMap( ( id ) => [
1487
+ { update: { _index: openSearch.trackerInput, _id: id } },
1488
+ { doc: updatedField },
1489
+ ] );
1490
+ const re= await bulkUpdate( body );
1491
+ logger.info( { getId: getId, re: re, storeId: inputData.storeId, fileDate: inputData.fileDate, function: 'tracking save - junk' } );
1492
+ }
1504
1493
  }
1505
1494
 
1506
1495
 
1507
1496
  // Employee Mapping
1508
- {
1509
- if ( inputData.employeeCount >0 ) {
1510
- const chunkedEmpMappingData = await filteredMap( inputData.employee );
1511
- empCount = chunkedEmpMappingData;
1512
- const getQuery = {
1513
- size: 10000,
1514
- _source: false, // do not fetch full source
1515
- stored_fields: [], // exclude all stored fields
1516
- query: {
1517
- bool: {
1518
- must: [
1519
- {
1520
- term: { 'store_id.keyword': inputData.storeId },
1521
- },
1522
- {
1523
- terms: { outputCluster: chunkedEmpMappingData },
1524
- },
1525
- {
1526
- term: { 'date.keyword': inputData.fileDate },
1527
- },
1528
- {
1529
- term: { 'module.keyword': 'CUSTOMER' },
1530
- },
1531
- ],
1532
- },
1497
+
1498
+ if ( inputData.employeeCount >0 ) {
1499
+ const chunkedEmpMappingData = await filteredMap( inputData.employee );
1500
+ empCount = chunkedEmpMappingData;
1501
+ const getQuery = {
1502
+ size: 10000,
1503
+ _source: false, // do not fetch full source
1504
+ stored_fields: [], // exclude all stored fields
1505
+ query: {
1506
+ bool: {
1507
+ must: [
1508
+ {
1509
+ term: { 'store_id.keyword': inputData.storeId },
1510
+ },
1511
+ {
1512
+ terms: { REIDCluster: chunkedEmpMappingData },
1513
+ },
1514
+ {
1515
+ term: { 'date.keyword': inputData.fileDate },
1516
+ },
1517
+ {
1518
+ term: { 'module.keyword': 'CUSTOMER' },
1519
+ },
1520
+ ],
1533
1521
  },
1522
+ },
1534
1523
 
1535
- };
1536
- const getId = await getOpenSearchData( openSearch.trackerInput, getQuery );
1537
- const ids = getId?.body?.hits?.total?.value || null;
1538
- if ( ids ) {
1539
- const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
1540
-
1541
- const updatedField = { EmployeeStatusFinal: 0 }; // your field updates
1542
- const body = temp.flatMap( ( id ) => [
1543
- { update: { _index: openSearch.trackerInput, _id: id } },
1544
- { doc: updatedField },
1545
- ] );
1546
- const re= await bulkUpdate( body );
1547
- logger.info( { getId: getId, re: re, storeId: inputData.storeId, fileDate: inputData.fileDate, function: 'tracking save - Employee' } );
1548
- }
1524
+ };
1525
+ const getId = await getOpenSearchData( openSearch.trackerInput, getQuery );
1526
+ const ids = getId?.body?.hits?.total?.value || null;
1527
+ if ( ids ) {
1528
+ const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
1529
+
1530
+ const updatedField = { EmployeeStatusFinal: 0 }; // your field updates
1531
+ const body = temp.flatMap( ( id ) => [
1532
+ { update: { _index: openSearch.trackerInput, _id: id } },
1533
+ { doc: updatedField },
1534
+ ] );
1535
+ const re= await bulkUpdate( body );
1536
+ logger.info( { getId: getId, re: re, storeId: inputData.storeId, fileDate: inputData.fileDate, function: 'tracking save - Employee' } );
1549
1537
  }
1550
1538
  }
1551
1539
 
@@ -1558,7 +1546,7 @@ if ( ids ) {
1558
1546
  chunk.map( async ( item ) => {
1559
1547
  const imgName= item.img_name;
1560
1548
  const mappedId= item.mappedid.map( ( m ) => m.img_name );
1561
- // customerCount=mappedId;
1549
+ customerCount.push( ...mappedId );
1562
1550
  const searchQuery = {
1563
1551
  size: 10000,
1564
1552
  _source: false, // do not fetch full source
@@ -1570,7 +1558,7 @@ if ( ids ) {
1570
1558
  term: { 'store_id.keyword': inputData.storeId },
1571
1559
  },
1572
1560
  {
1573
- terms: { outputCluster: mappedId },
1561
+ terms: { REIDCluster: mappedId },
1574
1562
  },
1575
1563
  {
1576
1564
  term: { 'date.keyword': inputData.fileDate },
@@ -1597,7 +1585,7 @@ if ( ids ) {
1597
1585
  } );
1598
1586
  }
1599
1587
 
1600
- if ( inputData.auditType == 'Audit' ) {
1588
+ if ( inputData.auditType !== 'ReAudit' ) {
1601
1589
  // junk Mapping
1602
1590
  const getJunkQuery = {
1603
1591
  size: 10000,
@@ -1663,7 +1651,7 @@ if ( ids ) {
1663
1651
  term: { 'module.keyword': 'CUSTOMER' },
1664
1652
  },
1665
1653
  {
1666
- term: { EmployeeStatusProposed: 1 },
1654
+ terms: { EmployeeStatusProposed: [ 1, 2 ] },
1667
1655
  },
1668
1656
  ],
1669
1657
  },
@@ -1685,46 +1673,45 @@ if ( ids ) {
1685
1673
  }
1686
1674
 
1687
1675
  // customer Mapping
1688
- // const getCusQuery = {
1689
- // size: 10000,
1690
- // _source: true, // do not fetch full source
1691
- // stored_fields: [], // exclude all stored fields
1692
- // query: {
1693
- // bool: {
1694
- // must_not: {
1695
- // terms: {
1696
- // outputCluster: customerCount, // how can i c=handle if incase empCount === []
1697
- // },
1698
- // },
1699
- // must: [
1700
- // {
1701
- // term: { 'store_id.keyword': inputData.storeId },
1702
- // },
1703
- // {
1704
- // term: { 'date.keyword': inputData.fileDate },
1705
- // },
1706
- // {
1707
- // term: { 'module.keyword': 'CUSTOMER' },
1708
- // },
1709
- // ],
1710
- // },
1711
- // },
1712
-
1713
- // };
1714
-
1715
- // const getCusId = await getOpenSearchData( openSearch.trackerInput, getCusQuery );
1716
- // const cusIds = getCusId?.body?.hits?.total?.value || null;
1717
- // if ( cusIds ) {
1718
- // const temp = getCusId?.body?.hits?.hits; // .map( ( item ) => {id:item._id,reidCluster:item._source.REIDCluster } );
1719
- // logger.info( { custoemrTemp: temp } );
1720
- // // const updatedField = ; // your field updates
1721
- // const body = temp.flatMap( ( id ) => [
1722
- // { update: { _index: openSearch.trackerInput, _id: id._id } },
1723
- // { doc: { outputCluster: id._source.REIDCluster } },
1724
- // ] );
1725
- // const re= await bulkUpdate( body );
1726
- // logger.info( { getCusId: getCusId, re: re, storeId: inputData.storeId, auditType: inputData.auditType, fileDate: inputData.fileDate, function: 'tracking save - junk false mapping' } );
1727
- // }
1676
+ const getCusQuery = {
1677
+ size: 10000,
1678
+ _source: false, // do not fetch full source
1679
+ stored_fields: [], // exclude all stored fields
1680
+ query: {
1681
+ bool: {
1682
+ must_not: {
1683
+ terms: {
1684
+ outputCluster: customerCount, // how can i c=handle if incase empCount === []
1685
+ },
1686
+ },
1687
+ must: [
1688
+ {
1689
+ term: { 'store_id.keyword': inputData.storeId },
1690
+ },
1691
+ {
1692
+ term: { 'date.keyword': inputData.fileDate },
1693
+ },
1694
+ {
1695
+ term: { 'module.keyword': 'CUSTOMER' },
1696
+ },
1697
+ ],
1698
+ },
1699
+ },
1700
+
1701
+ };
1702
+
1703
+ const getCusId = await getOpenSearchData( openSearch.trackerInput, getCusQuery );
1704
+ const cusIds = getCusId?.body?.hits?.total?.value || null;
1705
+ if ( cusIds ) {
1706
+ const temp = getCusId?.body?.hits?.hits.map( ( item ) => item._id );
1707
+ logger.info( { custoemrTemp: temp } );
1708
+ const body = temp.flatMap( ( id ) => [
1709
+ { update: { _index: openSearch.trackerInput, _id: id } },
1710
+ { doc: { outputCluster: 50000 } },
1711
+ ] );
1712
+ const re= await bulkUpdate( body );
1713
+ logger.info( { getCusId: getCusId, re: re, storeId: inputData.storeId, auditType: inputData.auditType, fileDate: inputData.fileDate, function: 'tracking save - junk false mapping' } );
1714
+ }
1728
1715
  }
1729
1716
  }
1730
1717
 
@@ -1768,7 +1755,7 @@ if ( ids ) {
1768
1755
  const ratio = ( ( storeAuditData.beforeCount - inputData.customerCount ) / storeAuditData.beforeCount );
1769
1756
  if ( ratio < clientData[0].auditConfigs.ratio &&
1770
1757
  inputData.auditType == 'Audit' &&
1771
- inputData.moduleType == 'traffic'
1758
+ inputData.moduleType == 'traffic1'
1772
1759
  ) {
1773
1760
  logger.info(
1774
1761
  `Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,