tango-app-api-infra 3.0.110-dev → 3.0.111-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._source.data.upload_Speed !='0 bytes' ) {
370
+ obj.Internetspeed = speedTest ? `${bytesToMB( speedTest._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 )} MB/sec` : '';
371
+ } else {
372
+ obj.Internetspeed = '0 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,
@@ -413,7 +418,11 @@ export async function edgeAppLogTable( req, res ) {
413
418
  }
414
419
 
415
420
  function bytesToMB( bytes ) {
416
- return bytes / ( 1024 * 1024 );
421
+ if ( bytes ) {
422
+ return bytes / ( 1024 * 1024 );
423
+ } else {
424
+ return 0;
425
+ }
417
426
  }
418
427
  function generateTimeSlots( startHour, endHour, interval, req ) {
419
428
  try {
@@ -455,180 +464,154 @@ export async function viewedgeAppLog( req, res ) {
455
464
  try {
456
465
  const store = await findOneStore( { storeId: req.body.storeId } );
457
466
  if ( !store ) {
458
- return res.sendError( 'Stores Not fond', 204 );
467
+ return res.sendError( 'Stores Not found', 204 );
459
468
  }
460
469
  const inputDate = dayjs( req.body.Date ).format( 'DD-MM-YYYY' );
461
470
  const fromTime = req.body.from;
462
471
  const toTime = req.body.to;
463
472
  let response = {};
464
473
 
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
- },
474
+ const queries = [
475
+ {
476
+ queryName: 'appStartTime',
477
+ query: {
478
+ size: 1,
479
+ query: {
480
+ bool: {
481
+ must: [
482
+ { term: { 'log_type.keyword': 'Application' } },
483
+ { term: { 'store_date.keyword': inputDate } },
484
+ { term: { 'storeId.keyword': req.body.storeId } },
485
+ { term: { 'log_subtype.keyword': 'AppStart_Time' } },
486
+ { term: { 'data.message.keyword': 'Login Success Event' } },
487
+ ],
495
488
  },
496
- ],
489
+ },
497
490
  },
498
491
  },
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
- },
492
+ {
493
+ queryName: 'appQuitTime',
494
+ query: {
495
+ size: 1,
496
+ query: {
497
+ bool: {
498
+ must: [
499
+ { term: { 'log_type.keyword': 'Application' } },
500
+ { term: { 'store_date.keyword': inputDate } },
501
+ { term: { 'storeId.keyword': req.body.storeId } },
502
+ { term: { 'log_subtype.keyword': 'App_Quit_Time' } },
503
+ { term: { 'data.message.keyword': 'App Quit With password' } },
504
+ ],
533
505
  },
534
- ],
535
-
506
+ },
507
+ sort: [ { timestamp: { order: 'desc' } } ],
536
508
  },
537
509
  },
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
- },
510
+ {
511
+ queryName: 'appCrashTime',
512
+ query: {
513
+ size: 1,
514
+ query: {
515
+ bool: {
516
+ must: [
517
+ { term: { 'log_type.keyword': 'Application' } },
518
+ { term: { 'store_date.keyword': inputDate } },
519
+ { term: { 'storeId.keyword': req.body.storeId } },
520
+ { term: { 'log_subtype.keyword': 'App_Close_Event' } },
521
+ ],
559
522
  },
560
- {
561
- 'term': {
562
- 'store_date.keyword': inputDate,
563
- },
523
+ },
524
+ sort: [ { timestamp: { order: 'desc' } } ],
525
+ },
526
+ },
527
+ {
528
+ queryName: 'screenStatus',
529
+ query: {
530
+ size: 100,
531
+ query: {
532
+ bool: {
533
+ must: [
534
+ { term: { 'log_type.keyword': 'Application' } },
535
+ { term: { 'store_date.keyword': inputDate } },
536
+ { term: { 'storeId.keyword': req.body.storeId } },
537
+ { term: { 'log_subtype.keyword': 'System_Status' } },
538
+ ],
564
539
  },
565
- {
566
- 'term': {
567
- 'storeId.keyword': req.body.storeId,
568
- },
540
+ },
541
+ sort: [ { timestamp: { order: 'asc' } } ],
542
+ },
543
+ },
544
+ {
545
+ queryName: 'fileCount',
546
+ query: {
547
+ size: 100,
548
+ query: {
549
+ bool: {
550
+ must: [
551
+ { term: { 'log_type.keyword': 'Application' } },
552
+ { term: { 'store_date.keyword': inputDate } },
553
+ { term: { 'storeId.keyword': req.body.storeId } },
554
+ { term: { 'log_subtype.keyword': 'Zip_File_Count' } },
555
+ ],
569
556
  },
570
- {
571
- 'term': {
572
- 'log_subtype.keyword': 'App_Close_Event',
573
- },
557
+ },
558
+ sort: [ { timestamp: { order: 'desc' } } ],
559
+ },
560
+ },
561
+ {
562
+ queryName: 'antiVirus',
563
+ query: {
564
+ size: 100,
565
+ query: {
566
+ bool: {
567
+ must: [
568
+ { term: { 'log_type.keyword': 'Application' } },
569
+ { term: { 'store_date.keyword': inputDate } },
570
+ { term: { 'storeId.keyword': req.body.storeId } },
571
+ { term: { 'log_subtype.keyword': 'Anti_Virus' } },
572
+ ],
574
573
  },
575
- ],
576
-
574
+ },
575
+ sort: [ { timestamp: { order: 'desc' } } ],
577
576
  },
578
577
  },
579
- 'sort': [
580
- { 'timestamp': { 'order': 'desc' } },
581
- ],
582
- };
578
+ ];
583
579
 
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
- }
580
+ const fetchLogs = queries.map( ( q ) =>
581
+ getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, q.query ),
582
+ );
583
+
584
+ const results = await Promise.all( fetchLogs );
585
+
586
+ const appStartTimeResult = results[0];
587
+ const appQuitTimeResult = results[1];
588
+ const appCrashTimeResult = results[2];
589
+ const screenStatusResult = results[3];
590
+ const fileCountResult = results[4];
591
+ const antiVirusResult = results[5];
592
+
593
+ response.appStartTime = appStartTimeResult.body.hits.hits.length > 0 ? appStartTimeResult.body.hits.hits[0]._source.data.occuringTime : '';
594
+
595
+ if ( appQuitTimeResult.body.hits.hits && appQuitTimeResult.body.hits.hits.length > 0 ) {
596
+ const quitTime = appQuitTimeResult.body.hits.hits.find( ( sourceData ) =>
597
+ Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ),
598
+ );
599
+ response.appQuitTime = quitTime ? quitTime._source.data.occuringTime : '';
591
600
  }
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
601
 
619
- },
620
- },
621
- 'sort': [
622
- { 'timestamp': { 'order': 'asc' } },
623
- ],
602
+ if ( appCrashTimeResult.body.hits.hits && appCrashTimeResult.body.hits.hits.length > 0 ) {
603
+ const crashTime = appCrashTimeResult.body.hits.hits.find( ( sourceData ) =>
604
+ Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ),
605
+ );
606
+ response.AppCrashtime = crashTime ? crashTime._source.data.occuringTime : '';
607
+ }
624
608
 
625
- } );
626
- if ( screenStatus&& screenStatus.body.hits.hits&&screenStatus.body.hits.hits.length > 0 ) {
609
+ if ( screenStatusResult.body.hits.hits && screenStatusResult.body.hits.hits.length > 0 ) {
627
610
  let suspendedTime;
628
611
  let resumedTime;
629
612
  const differences = [];
630
- for ( const sourceData of screenStatus.body.hits.hits ) {
631
- if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] )== Number( fromTime.split( ':' )[0] ) ) {
613
+ for ( const sourceData of screenStatusResult.body.hits.hits ) {
614
+ if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) ) {
632
615
  if ( sourceData._source.data.message.trim() === 'SYSTEM SUSPENDED' ) {
633
616
  suspendedTime = sourceData._source.data.occuringTime;
634
617
  } else if ( sourceData._source.data.message.trim() === 'SYSTEM RESUMED' ) {
@@ -647,103 +630,29 @@ export async function viewedgeAppLog( req, res ) {
647
630
  }
648
631
  }
649
632
  }
650
- response.screenStatus = differences.length>0?`${differences[0].minutes}Mins ${differences[0].seconds}Sec`:'';
633
+ response.screenStatus = differences.length > 0 ? `${differences[0].minutes}Mins ${differences[0].seconds}Sec` : '';
651
634
  }
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
635
 
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 ) {
636
+ if ( fileCountResult.body.hits.hits && fileCountResult.body.hits.hits.length > 0 ) {
688
637
  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
- }
638
+ response.files_generated = 0;
639
+ for ( const sourceData of fileCountResult.body.hits.hits ) {
640
+ if ( sourceData._source && Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) ) {
641
+ response.filesPushed += Number( sourceData._source.data.files_pushed );
642
+ response.files_generated += Number( sourceData._source.data.files_generated );
696
643
  }
697
644
  }
698
645
  } else {
699
646
  response.filesPushed = '';
700
- response.files_genrated = '';
647
+ response.files_generated = '';
701
648
  }
702
649
 
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
- }
650
+ if ( antiVirusResult.body.hits.hits && antiVirusResult.body.hits.hits.length > 0 ) {
651
+ const antivirusEvent = antiVirusResult.body.hits.hits.find( ( sourceData ) =>
652
+ Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) &&
653
+ sourceData._source.data.message === 'st-launch-1.0.exe is deleted',
654
+ );
655
+ response.antiVirus = antivirusEvent ? antivirusEvent._source.data.occuringTime : '';
747
656
  }
748
657
 
749
658
  res.sendSuccess( response );
@@ -753,6 +662,7 @@ export async function viewedgeAppLog( req, res ) {
753
662
  }
754
663
  }
755
664
 
665
+
756
666
  export async function cameraAngleChange( req, res ) {
757
667
  try {
758
668
  const angleChange = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).cameraAngleChange,