tango-app-api-infra 3.0.110-dev → 3.0.112-dev

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.
@@ -366,7 +366,12 @@ export async function edgeAppLogTable( req, res ) {
366
366
  const speedTest = speedTestData.find(
367
367
  ( item ) => Number( item._source.data.occuringTime.split( ':' )[0] ) === hour,
368
368
  );
369
- obj.Internetspeed = speedTest ? `${bytesToMB( speedTest._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 )} MB/sec` : '';
369
+ if ( speedTest&&speedTest._source.data.upload_Speed =='0 bytes' ) {
370
+ obj.Internetspeed = '0 MB/sec';
371
+ } else {
372
+ obj.Internetspeed = speedTest ? `${bytesToMB( speedTest._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 )} MB/sec` : '';
373
+ }
374
+
370
375
 
371
376
  // File counts
372
377
  const fileCounts = fileCountData.filter(
@@ -396,7 +401,7 @@ export async function edgeAppLogTable( req, res ) {
396
401
  if ( req.body.export ) {
397
402
  const exportData = timeSlots.map( ( element ) => ( {
398
403
  'Time Stamp': `${element.startTime}-${element.endTime}`,
399
- 'Downtime': element.downtime,
404
+ 'Downtime': element.downtime +'Mins',
400
405
  'Avg Internet Speed': element.Internetspeed,
401
406
  'Files Generated': element.files_generated,
402
407
  'Files Pushed': element.files_pushed,
@@ -455,180 +460,154 @@ export async function viewedgeAppLog( req, res ) {
455
460
  try {
456
461
  const store = await findOneStore( { storeId: req.body.storeId } );
457
462
  if ( !store ) {
458
- return res.sendError( 'Stores Not fond', 204 );
463
+ return res.sendError( 'Stores Not found', 204 );
459
464
  }
460
465
  const inputDate = dayjs( req.body.Date ).format( 'DD-MM-YYYY' );
461
466
  const fromTime = req.body.from;
462
467
  const toTime = req.body.to;
463
468
  let response = {};
464
469
 
465
-
466
- let appStartTimeQuery = {
467
- 'size': 100,
468
- 'query': {
469
- 'bool': {
470
- 'must': [
471
- {
472
- 'term': {
473
- 'log_type.keyword': 'Application',
474
- },
475
- },
476
- {
477
- 'term': {
478
- 'store_date.keyword': inputDate,
479
- },
480
- },
481
- {
482
- 'term': {
483
- 'storeId.keyword': req.body.storeId,
484
- },
485
- },
486
- {
487
- 'term': {
488
- 'log_subtype.keyword': 'AppStart_Time',
489
- },
490
- },
491
- {
492
- 'term': {
493
- 'data.message.keyword': 'Login Success Event',
494
- },
470
+ const queries = [
471
+ {
472
+ queryName: 'appStartTime',
473
+ query: {
474
+ size: 1,
475
+ query: {
476
+ bool: {
477
+ must: [
478
+ { term: { 'log_type.keyword': 'Application' } },
479
+ { term: { 'store_date.keyword': inputDate } },
480
+ { term: { 'storeId.keyword': req.body.storeId } },
481
+ { term: { 'log_subtype.keyword': 'AppStart_Time' } },
482
+ { term: { 'data.message.keyword': 'Login Success Event' } },
483
+ ],
495
484
  },
496
- ],
485
+ },
497
486
  },
498
487
  },
499
- };
500
- const appStartTime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, appStartTimeQuery );
501
-
502
- response.appStartTime = appStartTime.body.hits.hits.length > 0 ? appStartTime.body.hits.hits[0]._source.data.occuringTime : '';
503
-
504
- let appQuitTimeQuery = {
505
- 'size': 100,
506
- 'query': {
507
- 'bool': {
508
- 'must': [
509
- {
510
- 'term': {
511
- 'log_type.keyword': 'Application',
512
- },
513
- },
514
- {
515
- 'term': {
516
- 'store_date.keyword': inputDate,
517
- },
518
- },
519
- {
520
- 'term': {
521
- 'storeId.keyword': req.body.storeId,
522
- },
523
- },
524
- {
525
- 'term': {
526
- 'log_subtype.keyword': 'App_Quit_Time',
527
- },
528
- },
529
- {
530
- 'term': {
531
- 'data.message.keyword': 'App Quit With password',
532
- },
488
+ {
489
+ queryName: 'appQuitTime',
490
+ query: {
491
+ size: 1,
492
+ query: {
493
+ bool: {
494
+ must: [
495
+ { term: { 'log_type.keyword': 'Application' } },
496
+ { term: { 'store_date.keyword': inputDate } },
497
+ { term: { 'storeId.keyword': req.body.storeId } },
498
+ { term: { 'log_subtype.keyword': 'App_Quit_Time' } },
499
+ { term: { 'data.message.keyword': 'App Quit With password' } },
500
+ ],
533
501
  },
534
- ],
535
-
502
+ },
503
+ sort: [ { timestamp: { order: 'desc' } } ],
536
504
  },
537
505
  },
538
- 'sort': [
539
- { 'timestamp': { 'order': 'desc' } },
540
- ],
541
- };
542
- const appQuitTime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, appQuitTimeQuery );
543
- if ( appQuitTime.body.hits.hits&&appQuitTime.body.hits.hits.length > 0 ) {
544
- for ( const sourceData of appQuitTime.body.hits.hits ) {
545
- if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] )== Number( fromTime.split( ':' )[0] ) ) {
546
- response.appQuitTime = appQuitTime.body.hits.hits.length > 0 ? sourceData._source.data.occuringTime : '';
547
- }
548
- }
549
- }
550
- let appCrashTimeQuery = {
551
- 'size': 100,
552
- 'query': {
553
- 'bool': {
554
- 'must': [
555
- {
556
- 'term': {
557
- 'log_type.keyword': 'Application',
558
- },
506
+ {
507
+ queryName: 'appCrashTime',
508
+ query: {
509
+ size: 1,
510
+ query: {
511
+ bool: {
512
+ must: [
513
+ { term: { 'log_type.keyword': 'Application' } },
514
+ { term: { 'store_date.keyword': inputDate } },
515
+ { term: { 'storeId.keyword': req.body.storeId } },
516
+ { term: { 'log_subtype.keyword': 'App_Close_Event' } },
517
+ ],
559
518
  },
560
- {
561
- 'term': {
562
- 'store_date.keyword': inputDate,
563
- },
519
+ },
520
+ sort: [ { timestamp: { order: 'desc' } } ],
521
+ },
522
+ },
523
+ {
524
+ queryName: 'screenStatus',
525
+ query: {
526
+ size: 100,
527
+ query: {
528
+ bool: {
529
+ must: [
530
+ { term: { 'log_type.keyword': 'Application' } },
531
+ { term: { 'store_date.keyword': inputDate } },
532
+ { term: { 'storeId.keyword': req.body.storeId } },
533
+ { term: { 'log_subtype.keyword': 'System_Status' } },
534
+ ],
564
535
  },
565
- {
566
- 'term': {
567
- 'storeId.keyword': req.body.storeId,
568
- },
536
+ },
537
+ sort: [ { timestamp: { order: 'asc' } } ],
538
+ },
539
+ },
540
+ {
541
+ queryName: 'fileCount',
542
+ query: {
543
+ size: 100,
544
+ query: {
545
+ bool: {
546
+ must: [
547
+ { term: { 'log_type.keyword': 'Application' } },
548
+ { term: { 'store_date.keyword': inputDate } },
549
+ { term: { 'storeId.keyword': req.body.storeId } },
550
+ { term: { 'log_subtype.keyword': 'Zip_File_Count' } },
551
+ ],
569
552
  },
570
- {
571
- 'term': {
572
- 'log_subtype.keyword': 'App_Close_Event',
573
- },
553
+ },
554
+ sort: [ { timestamp: { order: 'desc' } } ],
555
+ },
556
+ },
557
+ {
558
+ queryName: 'antiVirus',
559
+ query: {
560
+ size: 100,
561
+ query: {
562
+ bool: {
563
+ must: [
564
+ { term: { 'log_type.keyword': 'Application' } },
565
+ { term: { 'store_date.keyword': inputDate } },
566
+ { term: { 'storeId.keyword': req.body.storeId } },
567
+ { term: { 'log_subtype.keyword': 'Anti_Virus' } },
568
+ ],
574
569
  },
575
- ],
576
-
570
+ },
571
+ sort: [ { timestamp: { order: 'desc' } } ],
577
572
  },
578
573
  },
579
- 'sort': [
580
- { 'timestamp': { 'order': 'desc' } },
581
- ],
582
- };
574
+ ];
583
575
 
584
- const appCrashTime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, appCrashTimeQuery );
585
- if ( appCrashTime.body.hits.hits&&appCrashTime.body.hits.hits.length > 0 ) {
586
- for ( const sourceData of appCrashTime.body.hits.hits ) {
587
- if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] )== Number( fromTime.split( ':' )[0] ) ) {
588
- response.AppCrashtime = appCrashTime.body.hits.hits.length > 0 ? sourceData._source.data.occuringTime : '';
589
- }
590
- }
576
+ const fetchLogs = queries.map( ( q ) =>
577
+ getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, q.query ),
578
+ );
579
+
580
+ const results = await Promise.all( fetchLogs );
581
+
582
+ const appStartTimeResult = results[0];
583
+ const appQuitTimeResult = results[1];
584
+ const appCrashTimeResult = results[2];
585
+ const screenStatusResult = results[3];
586
+ const fileCountResult = results[4];
587
+ const antiVirusResult = results[5];
588
+
589
+ response.appStartTime = appStartTimeResult.body.hits.hits.length > 0 ? appStartTimeResult.body.hits.hits[0]._source.data.occuringTime : '';
590
+
591
+ if ( appQuitTimeResult.body.hits.hits && appQuitTimeResult.body.hits.hits.length > 0 ) {
592
+ const quitTime = appQuitTimeResult.body.hits.hits.find( ( sourceData ) =>
593
+ Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ),
594
+ );
595
+ response.appQuitTime = quitTime ? quitTime._source.data.occuringTime : '';
591
596
  }
592
- const screenStatus = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, {
593
- 'size': 100,
594
- 'query': {
595
- 'bool': {
596
- 'must': [
597
- {
598
- 'term': {
599
- 'log_type.keyword': 'Application',
600
- },
601
- },
602
- {
603
- 'term': {
604
- 'store_date.keyword': inputDate,
605
- },
606
- },
607
- {
608
- 'term': {
609
- 'storeId.keyword': req.body.storeId,
610
- },
611
- },
612
- {
613
- 'term': {
614
- 'log_subtype.keyword': 'System_Status',
615
- },
616
- },
617
- ],
618
597
 
619
- },
620
- },
621
- 'sort': [
622
- { 'timestamp': { 'order': 'asc' } },
623
- ],
598
+ if ( appCrashTimeResult.body.hits.hits && appCrashTimeResult.body.hits.hits.length > 0 ) {
599
+ const crashTime = appCrashTimeResult.body.hits.hits.find( ( sourceData ) =>
600
+ Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ),
601
+ );
602
+ response.AppCrashtime = crashTime ? crashTime._source.data.occuringTime : '';
603
+ }
624
604
 
625
- } );
626
- if ( screenStatus&& screenStatus.body.hits.hits&&screenStatus.body.hits.hits.length > 0 ) {
605
+ if ( screenStatusResult.body.hits.hits && screenStatusResult.body.hits.hits.length > 0 ) {
627
606
  let suspendedTime;
628
607
  let resumedTime;
629
608
  const differences = [];
630
- for ( const sourceData of screenStatus.body.hits.hits ) {
631
- if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] )== Number( fromTime.split( ':' )[0] ) ) {
609
+ for ( const sourceData of screenStatusResult.body.hits.hits ) {
610
+ if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) ) {
632
611
  if ( sourceData._source.data.message.trim() === 'SYSTEM SUSPENDED' ) {
633
612
  suspendedTime = sourceData._source.data.occuringTime;
634
613
  } else if ( sourceData._source.data.message.trim() === 'SYSTEM RESUMED' ) {
@@ -647,103 +626,29 @@ export async function viewedgeAppLog( req, res ) {
647
626
  }
648
627
  }
649
628
  }
650
- response.screenStatus = differences.length>0?`${differences[0].minutes}Mins ${differences[0].seconds}Sec`:'';
629
+ response.screenStatus = differences.length > 0 ? `${differences[0].minutes}Mins ${differences[0].seconds}Sec` : '';
651
630
  }
652
- const FileCountQuery = {
653
- 'size': 100,
654
- 'query': {
655
- 'bool': {
656
- 'must': [
657
- {
658
- 'term': {
659
- 'log_type.keyword': 'Application',
660
- },
661
- },
662
- {
663
- 'term': {
664
- 'store_date.keyword': inputDate,
665
- },
666
- },
667
- {
668
- 'term': {
669
- 'storeId.keyword': req.body.storeId,
670
- },
671
- },
672
- {
673
- 'term': {
674
- 'log_subtype.keyword': 'Zip_File_Count',
675
- },
676
- },
677
- ],
678
631
 
679
- },
680
- },
681
-
682
- 'sort': [
683
- { 'timestamp': { 'order': 'desc' } },
684
- ],
685
- };
686
- const newFilesCount = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, FileCountQuery );
687
- if ( newFilesCount&& newFilesCount.body.hits && newFilesCount.body.hits.hits.length > 0 ) {
632
+ if ( fileCountResult.body.hits.hits && fileCountResult.body.hits.hits.length > 0 ) {
688
633
  response.filesPushed = 0;
689
- response.files_genrated = 0;
690
- for ( const sourcedata of newFilesCount.body.hits.hits ) {
691
- if ( sourcedata._source ) {
692
- if ( Number( sourcedata._source.data.occuringTime.split( ':' )[0] )==Number( fromTime.split( ':' )[0] ) ) {
693
- response.filesPushed = response.filesPushed+Number( sourcedata._source.data.files_pushed );
694
- response.files_genrated = response.files_generated+Number( sourcedata._source.data.files_generated );
695
- }
634
+ response.files_generated = 0;
635
+ for ( const sourceData of fileCountResult.body.hits.hits ) {
636
+ if ( sourceData._source && Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) ) {
637
+ response.filesPushed += Number( sourceData._source.data.files_pushed );
638
+ response.files_generated += Number( sourceData._source.data.files_generated );
696
639
  }
697
640
  }
698
641
  } else {
699
642
  response.filesPushed = '';
700
- response.files_genrated = '';
643
+ response.files_generated = '';
701
644
  }
702
645
 
703
-
704
- const antiVirus = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, {
705
- 'size': 100,
706
- 'query': {
707
- 'bool': {
708
- 'must': [
709
- {
710
- 'term': {
711
- 'log_type.keyword': 'Application',
712
- },
713
- },
714
- {
715
- 'term': {
716
- 'storeId.keyword': req.body.storeId,
717
- },
718
- },
719
- {
720
- 'term': {
721
- 'store_date.keyword': inputDate,
722
- },
723
- },
724
- {
725
- 'term': {
726
- 'log_subtype.keyword': 'Anti_Virus',
727
- },
728
- },
729
- ],
730
-
731
- },
732
- },
733
- 'sort': [
734
- { 'timestamp': { 'order': 'desc' } },
735
- ],
736
- },
737
- );
738
- // response.antiVirus = antiVirus.body.hits.hits.length > 0 && antiVirus.body.hits.hits[0]._source.data.message == 'st-launch-1.0.exe is deleted' ? antiVirus.body.hits.hits[0]._source.data.occuringTime : '';
739
- if ( antiVirus.body.hits.hits&&antiVirus.body.hits.hits.length > 0 ) {
740
- for ( const sourceData of antiVirus.body.hits.hits ) {
741
- if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] )== Number( fromTime.split( ':' )[0] ) ) {
742
- if ( sourceData._source.data.message == 'st-launch-1.0.exe is deleted' ) {
743
- response.antiVirus = antiVirus.body.hits.hits.length > 0 ? sourceData._source.data.occuringTime : '';
744
- }
745
- }
746
- }
646
+ if ( antiVirusResult.body.hits.hits && antiVirusResult.body.hits.hits.length > 0 ) {
647
+ const antivirusEvent = antiVirusResult.body.hits.hits.find( ( sourceData ) =>
648
+ Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) &&
649
+ sourceData._source.data.message === 'st-launch-1.0.exe is deleted',
650
+ );
651
+ response.antiVirus = antivirusEvent ? antivirusEvent._source.data.occuringTime : '';
747
652
  }
748
653
 
749
654
  res.sendSuccess( response );
@@ -753,6 +658,7 @@ export async function viewedgeAppLog( req, res ) {
753
658
  }
754
659
  }
755
660
 
661
+
756
662
  export async function cameraAngleChange( req, res ) {
757
663
  try {
758
664
  const angleChange = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).cameraAngleChange,