tango-app-api-audit 3.4.5 → 3.4.7

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.4.5",
3
+ "version": "3.4.7",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1927,10 +1927,16 @@ export async function clientMetrics( req, res ) {
1927
1927
  return res.sendError( 'No Data Found', 204 );
1928
1928
  }
1929
1929
 
1930
- query.push(
1931
- { $skip: offset },
1932
- { $limit: limit },
1933
- );
1930
+ if ( inputData.isExport ) {
1931
+ query.push( { $limit: 10000 } );
1932
+ } else {
1933
+ query.push( {
1934
+ $skip: offset,
1935
+ },
1936
+ {
1937
+ $limit: limit,
1938
+ } );
1939
+ }
1934
1940
  if ( inputData.isExport ) {
1935
1941
  query.push(
1936
1942
  {
@@ -2311,7 +2317,7 @@ export async function userMetrics( req, res ) {
2311
2317
  startTime: 1,
2312
2318
  endTime: 1,
2313
2319
  totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
2314
- beforeCount: 1,
2320
+ beforeCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$beforeCount', 0 ] },
2315
2321
  afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
2316
2322
  createdAt: 1,
2317
2323
  },
@@ -2504,10 +2510,16 @@ export async function userMetrics( req, res ) {
2504
2510
  return res.sendError( 'No Data Found', 204 );
2505
2511
  }
2506
2512
 
2507
- query.push(
2508
- { $skip: offset },
2509
- { $limit: limit },
2510
- );
2513
+ if ( inputData.isExport ) {
2514
+ query.push( { $limit: 10000 } );
2515
+ } else {
2516
+ query.push( {
2517
+ $skip: offset,
2518
+ },
2519
+ {
2520
+ $limit: limit,
2521
+ } );
2522
+ }
2511
2523
  if ( inputData.isExport ) {
2512
2524
  query.push(
2513
2525
  {
@@ -4536,52 +4548,208 @@ export async function getUserAuditCountMTD( req, res ) {
4536
4548
  export async function auditViewLogs( req, res ) {
4537
4549
  try {
4538
4550
  const inputData = req.query;
4551
+ let logsQuery;
4539
4552
  const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
4540
4553
  const logData =[];
4541
- let logsQuery = {
4542
- 'size': 100,
4543
- 'query': {
4544
- 'bool': {
4545
- 'must': [
4546
- {
4547
- 'term': {
4548
- 'logData.fileDate.keyword': inputData.fileDate,
4554
+ if ( inputData.moduleType == 'traffic' ||inputData.moduleType == 'zone' ) {
4555
+ logsQuery = {
4556
+ 'size': 100,
4557
+ 'query': {
4558
+ 'bool': {
4559
+ 'must': [
4560
+ {
4561
+ 'term': {
4562
+ 'logData.fileDate.keyword': inputData.fileDate,
4563
+ },
4564
+ },
4565
+ {
4566
+ 'term': {
4567
+ 'logData.storeId.keyword': inputData.storeId,
4568
+ },
4569
+ },
4570
+ {
4571
+ 'term': {
4572
+ 'logData.moduleType.keyword': inputData.moduleType,
4573
+ },
4574
+ },
4575
+ {
4576
+ 'term': {
4577
+ 'logData.zoneName.keyword': inputData.zoneName,
4578
+ },
4579
+ },
4580
+ {
4581
+ 'terms': {
4582
+ 'logSubType.keyword': [ 'auditDone', 'reTrigger' ],
4583
+ },
4584
+ },
4585
+ ],
4586
+ },
4587
+ },
4588
+ };
4589
+ } else {
4590
+ switch ( inputData.moduleType ) {
4591
+ case 'unattended-customer':
4592
+ logsQuery = {
4593
+ 'size': 100,
4594
+ 'query': {
4595
+ 'bool': {
4596
+ 'must': [
4597
+ {
4598
+ 'term': {
4599
+ 'data.fileDate.keyword': inputData.fileDate,
4600
+ },
4601
+ },
4602
+ {
4603
+ 'term': {
4604
+ 'data.storeId.keyword': inputData.storeId,
4605
+ },
4606
+ },
4607
+ {
4608
+ 'term': {
4609
+ 'data.moduleType.keyword': inputData.moduleType,
4610
+ },
4611
+ },
4612
+ {
4613
+ 'term': {
4614
+ 'data.tempId.keyword': inputData.tempId,
4615
+ },
4616
+ },
4617
+ {
4618
+ 'terms': {
4619
+ 'logSubType.keyword': [ 'auditDone', 'reTrigger' ],
4620
+ },
4621
+ },
4622
+ ],
4549
4623
  },
4550
4624
  },
4551
- {
4552
- 'term': {
4553
- 'logData.storeId.keyword': inputData.storeId,
4625
+ };
4626
+ break;
4627
+ case 'left-in-middle':
4628
+ logsQuery = {
4629
+ 'size': 100,
4630
+ 'query': {
4631
+ 'bool': {
4632
+ 'must': [
4633
+ {
4634
+ 'term': {
4635
+ 'data.fileDate.keyword': inputData.fileDate,
4636
+ },
4637
+ },
4638
+ {
4639
+ 'term': {
4640
+ 'data.storeId.keyword': inputData.storeId,
4641
+ },
4642
+ },
4643
+ {
4644
+ 'term': {
4645
+ 'data.moduleType.keyword': inputData.moduleType,
4646
+ },
4647
+ },
4648
+ {
4649
+ 'term': {
4650
+ 'data.question.keyword': inputData.question,
4651
+ },
4652
+ },
4653
+ {
4654
+ 'terms': {
4655
+ 'logSubType.keyword': [ 'auditDone', 'reTrigger' ],
4656
+ },
4657
+ },
4658
+ ],
4554
4659
  },
4555
4660
  },
4556
- {
4557
- 'term': {
4558
- 'logData.moduleType.keyword': inputData.moduleType,
4661
+ };
4662
+ break;
4663
+ case 'uniform-detection':
4664
+ case 'mobile-detection': // Handle both in the same block
4665
+ logsQuery = {
4666
+ 'size': 100,
4667
+ 'query': {
4668
+ 'bool': {
4669
+ 'must': [
4670
+ {
4671
+ 'term': {
4672
+ 'logData.fileDate.keyword': inputData.fileDate,
4673
+ },
4674
+ },
4675
+ {
4676
+ 'term': {
4677
+ 'logData.storeId.keyword': inputData.storeId,
4678
+ },
4679
+ },
4680
+ {
4681
+ 'term': {
4682
+ 'logData.moduleType.keyword': inputData.moduleType,
4683
+ },
4684
+ },
4685
+ {
4686
+ 'terms': {
4687
+ 'logSubType.keyword': [ 'auditDone', 'reTrigger' ],
4688
+ },
4689
+ },
4690
+ ],
4559
4691
  },
4560
4692
  },
4561
- {
4562
- 'terms': {
4563
- 'logSubType.keyword': [ 'auditDone', 'reAuditPush', 'reTrigger' ],
4693
+ };
4694
+ break;
4695
+ case 'camera-angle-change':
4696
+ logsQuery = {
4697
+ 'size': 100,
4698
+ 'query': {
4699
+ 'bool': {
4700
+ 'must': [
4701
+ {
4702
+ 'term': {
4703
+ 'data.fileDate.keyword': inputData.fileDate,
4704
+ },
4705
+ },
4706
+ {
4707
+ 'term': {
4708
+ 'data.storeId.keyword': inputData.storeId,
4709
+ },
4710
+ },
4711
+ {
4712
+ 'term': {
4713
+ 'data.moduleType.keyword': inputData.moduleType,
4714
+ },
4715
+ },
4716
+ {
4717
+ 'term': {
4718
+ 'data.streamName.keyword': inputData.streamName,
4719
+ },
4720
+ },
4721
+ {
4722
+ 'terms': {
4723
+ 'logSubType.keyword': [ 'auditDone', 'reTrigger' ],
4724
+ },
4725
+ },
4726
+ ],
4564
4727
  },
4565
4728
  },
4566
- ],
4567
- },
4568
- },
4569
- };
4729
+ };
4730
+ break;
4731
+ default:
4732
+ return res.sendError( 'Please give valid modueType', 400 );
4733
+ }
4734
+ }
4570
4735
  const logs = await getOpenSearchData( parsedOpenSearch.auditLog, logsQuery );
4571
4736
  logger.info( { logs: logs.body.hits, inputData: inputData, auditLog: parsedOpenSearch.auditLog } );
4572
4737
  if ( logs.body.hits.hits.length > 0 ) {
4573
- if ( logs.body.hits.hits[0]._source.logSubType == 'auditDone' ) {
4574
- const convertedTime = await convertTimestampToDateTime( logs.body.hits.hits[0]._source.logData.endTime );
4575
- logData.push( {
4576
- ...logs.body.hits.hits[0]._source, // Spread the _source object
4577
- time: convertedTime, // Add the converted time
4578
- } );
4579
- } else {
4580
- const convertedTime = await convertTimestampToDateTime( logs.body.hits.hits[0]._source.createdAt );
4581
- logData.push( {
4582
- ...logs.body.hits.hits[0]._source, // Spread the _source object
4583
- time: convertedTime, // Add the converted time
4584
- } );
4738
+ const sourcesArray = logs.body.hits.hits.map( ( hit ) => hit._source );
4739
+ for ( const i of sourcesArray ) { // Loop through sourcesArray, not result._doc.camera
4740
+ if ( i.logSubType == 'auditDone' ) {
4741
+ const convertedTime = await convertTimestampToDateTime( i.logData.endTime );
4742
+ logData.push( {
4743
+ ...i, // Spread the individual log object
4744
+ time: convertedTime, // Add the converted time
4745
+ } );
4746
+ } else {
4747
+ const convertedTime = await convertTimestampToDateTime( i.createdAt );
4748
+ logData.push( {
4749
+ ...i, // Spread the individual log object
4750
+ time: convertedTime, // Add the converted time
4751
+ } );
4752
+ }
4585
4753
  }
4586
4754
  return res.sendSuccess( logData );
4587
4755
  } else {
@@ -4600,8 +4768,19 @@ export async function convertTimestampToDateTime( timestamp ) {
4600
4768
  timestamp = Math.floor( timestamp / 1000 ); // Convert to milliseconds if needed
4601
4769
  }
4602
4770
 
4603
- // Create a new Date object
4604
- const date = new Date( timestamp );
4771
+ // Add 5 hours and 30 minutes in milliseconds
4772
+ const timeOffset = ( 5 * 60 * 60 * 1000 ) + ( 30 * 60 * 1000 );
4773
+
4774
+ // Ensure the timestamp is valid by adding the offset correctly
4775
+ const adjustedTimestamp = timestamp + timeOffset;
4776
+
4777
+ // Create a new Date object using the adjusted timestamp
4778
+ const date = new Date( adjustedTimestamp );
4779
+
4780
+ // Ensure the date is valid (timestamp may be invalid)
4781
+ if ( isNaN( date.getTime() ) ) {
4782
+ throw new Error( 'Invalid timestamp provided' );
4783
+ }
4605
4784
 
4606
4785
  // Format the date and time components
4607
4786
  const year = date.getFullYear();
@@ -4615,3 +4794,5 @@ export async function convertTimestampToDateTime( timestamp ) {
4615
4794
  // Return formatted date and time string
4616
4795
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
4617
4796
  }
4797
+
4798
+
@@ -1192,7 +1192,7 @@ export async function getAuditFile( req, res ) {
1192
1192
  const logData = {
1193
1193
  userId: insertData.userId,
1194
1194
  userName: userdata.name,
1195
- logType: 'audit',
1195
+ logType: 'traxAudit',
1196
1196
  logSubType: 'auditStart',
1197
1197
  data: {
1198
1198
  fileDate: msg.fileDate,
@@ -1360,7 +1360,7 @@ export async function getUpdatedFile( req, res ) {
1360
1360
  const logData = {
1361
1361
  userId: req.user._id,
1362
1362
  userName: userdata.name,
1363
- logType: 'audit',
1363
+ logType: 'traxAudit',
1364
1364
  logSubType: 'auditStart',
1365
1365
  data: {
1366
1366
  fileDate: msg.fileDate,
@@ -2600,10 +2600,9 @@ export async function storeMetrics( req, res ) {
2600
2600
  result.forEach( ( element ) => {
2601
2601
  const temp ={
2602
2602
  'File Date': element.fileDate,
2603
- 'Store ID': element.storeId,
2604
2603
  'Store Name': element.storeName,
2605
- 'Client Id': element.clientId,
2606
- 'Client Name': element.clientName,
2604
+ 'Store ID': element.storeId,
2605
+ 'Product Type': element.value,
2607
2606
  'User Name': element.userName,
2608
2607
  'User Email': element.userEmail,
2609
2608
  'Audit Type': element.auditType,
@@ -2613,16 +2612,19 @@ export async function storeMetrics( req, res ) {
2613
2612
  case 'camera-angle-change':
2614
2613
  temp['stream Name'] = element.streamName;
2615
2614
  temp['User Comments'] = element.userComments;
2615
+ temp['Result'] = element.answer;
2616
2616
  break;
2617
2617
  case 'unattended-customer':
2618
2618
  temp['Customer ID'] = element.tempId;
2619
2619
  temp['Question'] = element.question;
2620
2620
  temp['User Comments'] = element.userComments;
2621
+ temp['Result'] = element.answer;
2621
2622
  break;
2622
2623
  case 'left-in-middle':
2623
2624
  temp['Question'] = element.question;
2624
2625
  temp['User Comments'] = element.userComments;
2625
2626
  temp['Status'] = toCamelCase( element.auditStatus );
2627
+ temp['Result'] = element.answer;
2626
2628
  break;
2627
2629
  case 'mobile-detection':
2628
2630
  temp['Before Count'] = element.beforeCount;