tango-app-api-infra 3.0.109-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,172 +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
- const inputDate = dayjs( req.body.Date ).format( 'YYYY-MM-DD' ); // Specify the date you want to add the times to
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': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
479
- },
480
- },
481
- {
482
- 'term': {
483
- 'store_id.keyword': req.body.storeId,
484
- },
485
- },
486
- {
487
- 'term': {
488
- 'log_subtype.keyword': 'AppStart_Time',
489
- },
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
+ ],
490
488
  },
491
- ],
492
-
489
+ },
493
490
  },
494
491
  },
495
- };
496
- const appStartTime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, appStartTimeQuery );
497
-
498
- response.appStartTime = appStartTime.body.hits.hits.length > 0 ? appStartTime.body.hits.hits[0]._source.data.occuringTime : '';
499
-
500
- let appQuitTimeQuery = {
501
- 'size': 100,
502
- 'query': {
503
- 'bool': {
504
- 'must': [
505
- {
506
- 'term': {
507
- 'log_type.keyword': 'Application',
508
- },
509
- },
510
- {
511
- 'term': {
512
- 'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
513
- },
514
- },
515
- {
516
- 'term': {
517
- 'store_id.keyword': req.body.storeId,
518
- },
519
- },
520
- {
521
- 'term': {
522
- 'log_subtype.keyword': 'App_Quit',
523
- },
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
+ ],
524
505
  },
525
- ],
526
-
506
+ },
507
+ sort: [ { timestamp: { order: 'desc' } } ],
527
508
  },
528
509
  },
529
- 'sort': [
530
- { 'timestamp': { 'order': 'desc' } },
531
- ],
532
- };
533
- const appQuitTime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, appQuitTimeQuery );
534
- if ( appQuitTime.body.hits.hits&&appQuitTime.body.hits.hits.length > 0 ) {
535
- for ( const sourceData of appQuitTime.body.hits.hits ) {
536
- if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] )== Number( fromTime.split( ':' )[0] ) ) {
537
- response.appQuitTime = appQuitTime.body.hits.hits.length > 0 ? sourceData._source.data.occuringTime : '';
538
- }
539
- }
540
- }
541
- let appCrashTimeQuery = {
542
- 'size': 100,
543
- 'query': {
544
- 'bool': {
545
- 'must': [
546
- {
547
- 'term': {
548
- 'log_type.keyword': 'Application',
549
- },
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
+ ],
550
522
  },
551
- {
552
- 'term': {
553
- 'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
554
- },
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
+ ],
555
539
  },
556
- {
557
- 'term': {
558
- 'store_id.keyword': req.body.storeId,
559
- },
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
+ ],
560
556
  },
561
- {
562
- 'term': {
563
- 'log_subtype.keyword': 'App_Crash',
564
- },
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
+ ],
565
573
  },
566
- ],
567
-
574
+ },
575
+ sort: [ { timestamp: { order: 'desc' } } ],
568
576
  },
569
577
  },
570
- 'sort': [
571
- { 'timestamp': { 'order': 'desc' } },
572
- ],
573
- };
578
+ ];
574
579
 
575
- const appCrashTime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, appCrashTimeQuery );
576
- if ( appCrashTime.body.hits.hits&&appCrashTime.body.hits.hits.length > 0 ) {
577
- for ( const sourceData of appCrashTime.body.hits.hits ) {
578
- if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] )== Number( fromTime.split( ':' )[0] ) ) {
579
- response.AppCrashtime = appCrashTime.body.hits.hits.length > 0 ? sourceData._source.data.occuringTime : '';
580
- }
581
- }
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 : '';
582
600
  }
583
- const screenStatus = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, {
584
- 'size': 100,
585
- 'query': {
586
- 'bool': {
587
- 'must': [
588
- {
589
- 'term': {
590
- 'log_type.keyword': 'Application',
591
- },
592
- },
593
- {
594
- 'term': {
595
- 'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
596
- },
597
- },
598
- {
599
- 'term': {
600
- 'store_id.keyword': req.body.storeId,
601
- },
602
- },
603
- {
604
- 'term': {
605
- 'log_subtype.keyword': 'System_Status',
606
- },
607
- },
608
- ],
609
601
 
610
- },
611
- },
612
- 'sort': [
613
- { 'timestamp': { 'order': 'asc' } },
614
- ],
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
+ }
615
608
 
616
- } );
617
- if ( screenStatus&& screenStatus.body.hits.hits&&screenStatus.body.hits.hits.length > 0 ) {
609
+ if ( screenStatusResult.body.hits.hits && screenStatusResult.body.hits.hits.length > 0 ) {
618
610
  let suspendedTime;
619
611
  let resumedTime;
620
612
  const differences = [];
621
-
622
- for ( const sourceData of screenStatus.body.hits.hits ) {
623
- 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] ) ) {
624
615
  if ( sourceData._source.data.message.trim() === 'SYSTEM SUSPENDED' ) {
625
616
  suspendedTime = sourceData._source.data.occuringTime;
626
617
  } else if ( sourceData._source.data.message.trim() === 'SYSTEM RESUMED' ) {
@@ -639,96 +630,30 @@ export async function viewedgeAppLog( req, res ) {
639
630
  }
640
631
  }
641
632
  }
642
- 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` : '';
643
634
  }
644
- const FileCountQuery = {
645
- 'size': 100,
646
- 'query': {
647
- 'bool': {
648
- 'must': [
649
- {
650
- 'term': {
651
- 'log_type.keyword': 'Application',
652
- },
653
- },
654
- {
655
- 'term': {
656
- 'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
657
- },
658
- },
659
- {
660
- 'term': {
661
- 'storeId.keyword': req.body.storeId,
662
- },
663
- },
664
- {
665
- 'term': {
666
- 'log_subtype.keyword': 'Zip_File_Count',
667
- },
668
- },
669
- ],
670
-
671
- },
672
- },
673
635
 
674
- 'sort': [
675
- { 'timestamp': { 'order': 'desc' } },
676
- ],
677
- };
678
- const newFilesCount = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, FileCountQuery );
679
- if ( newFilesCount&& newFilesCount.body.hits && newFilesCount.body.hits.hits.length > 0 ) {
636
+ if ( fileCountResult.body.hits.hits && fileCountResult.body.hits.hits.length > 0 ) {
680
637
  response.filesPushed = 0;
681
- response.files_genrated = 0;
682
- for ( const sourcedata of newFilesCount.body.hits.hits ) {
683
- if ( sourcedata._source ) {
684
- if ( Number( sourcedata._source.data.occuringTime.split( ':' )[0] )==Number( fromTime.split( ':' )[0] ) ) {
685
- response.filesPushed = response.filesPushed+Number( sourcedata._source.data.files_pushed );
686
- response.files_genrated = response.files_generated+Number( sourcedata._source.data.files_generated );
687
- }
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 );
688
643
  }
689
644
  }
690
645
  } else {
691
646
  response.filesPushed = '';
692
- response.files_genrated = '';
647
+ response.files_generated = '';
693
648
  }
694
649
 
695
-
696
- const antiVirus = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, {
697
- 'size': 100,
698
- 'query': {
699
- 'bool': {
700
- 'must': [
701
- {
702
- 'term': {
703
- 'log_type.keyword': 'Application',
704
- },
705
- },
706
- {
707
- 'term': {
708
- 'store_id.keyword': req.body.storeId,
709
- },
710
- },
711
- {
712
- 'term': {
713
- 'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
714
- },
715
- },
716
- {
717
- 'term': {
718
- 'log_subtype.keyword': 'Anti_Virus',
719
- },
720
- },
721
- ],
722
-
723
- },
724
- },
725
- 'sort': [
726
- { 'timestamp': { 'order': 'desc' } },
727
- ],
728
- },
729
- );
730
- 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 : '';
731
-
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 : '';
656
+ }
732
657
 
733
658
  res.sendSuccess( response );
734
659
  } catch ( error ) {
@@ -737,6 +662,7 @@ export async function viewedgeAppLog( req, res ) {
737
662
  }
738
663
  }
739
664
 
665
+
740
666
  export async function cameraAngleChange( req, res ) {
741
667
  try {
742
668
  const angleChange = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).cameraAngleChange,
@@ -55,24 +55,24 @@ export async function validateTicket( req, res, next ) {
55
55
  {
56
56
  'basicDetails.storeId': req.body.basicDetails.storeId,
57
57
  'issueType': 'infra',
58
- 'issueDate': new Date( req.body.Date ),
58
+ 'status': { $ne: 'closed' },
59
59
  },
60
60
  );
61
61
  if ( Ticket ) {
62
- return res.sendSuccess( 'Infra Ticket Already Exists for the day' );
62
+ return res.sendSuccess( 'Infra Ticket Already Exists' );
63
63
  }
64
64
 
65
- let refreshTicket = await findOneTangoTicket(
66
- {
67
- 'basicDetails.storeId': req.body.basicDetails.storeId,
68
- 'issueType': 'infra',
69
- 'status': { $ne: 'closed' },
70
- 'ticketDetails.ticketRefreshTime': { $lte: new Date() },
71
- },
72
- );
73
- if ( refreshTicket ) {
74
- return res.sendSuccess( 'refreshTicket Ticket Already Exists for the Store' );
75
- }
65
+ // let refreshTicket = await findOneTangoTicket(
66
+ // {
67
+ // 'basicDetails.storeId': req.body.basicDetails.storeId,
68
+ // 'issueType': 'infra',
69
+ // 'status': { $ne: 'closed' },
70
+ // 'ticketDetails.ticketRefreshTime': { $lte: new Date() },
71
+ // },
72
+ // );
73
+ // if ( refreshTicket ) {
74
+ // return res.sendSuccess( 'refreshTicket Ticket Already Exists for the Store' );
75
+ // }
76
76
  } else if ( req.body.issueType == 'installation' ) {
77
77
  let Ticket = await findOneTangoTicket(
78
78
  {