tango-app-api-infra 3.0.57-dev → 3.0.58-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-infra",
3
- "version": "3.0.57-dev",
3
+ "version": "3.0.58-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -3,7 +3,7 @@
3
3
  import { aggregateTangoTicket, createTangoTicket, findOneTangoTicket, updateOneTangoTicket, updateManyTangoTicket, findTangoTicket } from '../services/tangoTicket.service.js';
4
4
  import { createinfraReason, findinfraReason } from '../services/infraReason.service.js';
5
5
  import { updateOneStore, findStore } from '../services/store.service.js';
6
- import { logger, fileUpload, signedUrl, sendEmailWithSES, getOpenSearchData, appConfig, getUTC } from 'tango-app-api-middleware';
6
+ import { logger, fileUpload, signedUrl, sendEmailWithSES, getOpenSearchData, download, appConfig, getUTC } from 'tango-app-api-middleware';
7
7
  import { aggregateUser, updateOneUser } from '../services/user.service.js';
8
8
  import { updateoneClient } from '../services/client.service.js';
9
9
  import dayjs from 'dayjs';
@@ -825,7 +825,17 @@ export async function infraTable( req, res ) {
825
825
  const exportdata = [];
826
826
  result.forEach( ( element ) => {
827
827
  exportdata.push( {
828
-
828
+ 'ticketId': element.ticketId,
829
+ 'issueDate': dayjs( element.issueDate ).format( 'DD-MM-YYYY' ),
830
+ 'storeId': element.storeId,
831
+ 'storeName': element.storeName,
832
+ 'clientId': element.clientId,
833
+ 'clientName': element.clientName,
834
+ 'userName': element.userName,
835
+ 'userEmail': element.userEmail,
836
+ 'Status': element.status,
837
+ 'StatusDetails': element.primaryIssue,
838
+ 'SubIssue': element.secondaryIssue,
829
839
  } );
830
840
  } );
831
841
  await download( exportdata, res );
@@ -911,7 +921,7 @@ export async function installationTable( req, res ) {
911
921
  createdAt: 1,
912
922
  ticketId: 1,
913
923
  addressingUser: 1,
914
- installationStatus: 1,
924
+ installationStatus: { $ifNull: [ '$installationStatus', '-' ] },
915
925
  issueDate: { $ifNull: [ '$issueDate', '' ] },
916
926
  status: 1,
917
927
  primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
@@ -1051,7 +1061,17 @@ export async function installationTable( req, res ) {
1051
1061
  const exportdata = [];
1052
1062
  result.forEach( ( element ) => {
1053
1063
  exportdata.push( {
1054
-
1064
+ 'ticketId': element.ticketId,
1065
+ 'issueDate': dayjs( element.issueDate ).format( 'DD-MM-YYYY' ),
1066
+ 'storeId': element.storeId,
1067
+ 'storeName': element.storeName,
1068
+ 'clientId': element.clientId,
1069
+ 'clientName': element.clientName,
1070
+ 'userName': element.userName,
1071
+ 'userEmail': element.userEmail,
1072
+ 'Status': element.installationStatus,
1073
+ 'StatusDetails': element.primaryIssue,
1074
+ 'SubIssue': element.secondaryIssue,
1055
1075
  } );
1056
1076
  } );
1057
1077
  await download( exportdata, res );
@@ -1084,16 +1104,17 @@ export async function assignTicket( req, res ) {
1084
1104
  }
1085
1105
  export async function storeFilter( req, res ) {
1086
1106
  try {
1087
- let stores = await findTangoTicket( { 'issueType': req.body.issueType, 'basicDetails.storeId': { $exists: true } }, { 'basicDetails.storeId': 1 } );
1107
+ let stores = await findTangoTicket( { 'issueType': req.body.issueType, 'basicDetails.clientId': req.body.clientId, 'basicDetails.storeId': { $exists: true } }, { 'basicDetails.storeId': 1 } );
1088
1108
  const uniqueStoreIds = [ ...new Set( stores.map( ( store ) => store.basicDetails.storeId ) ) ];
1089
1109
  const uniqueStoreObjects = uniqueStoreIds.map( ( storeId ) => ( { 'storeId': storeId } ) );
1090
1110
 
1091
1111
  if ( uniqueStoreObjects.length>0 ) {
1092
1112
  res.sendSuccess( { count: uniqueStoreObjects.length, data: uniqueStoreObjects } );
1093
1113
  } else {
1094
- res.sendError( 'No data' );
1114
+ res.sendError( 'No data', 204 );
1095
1115
  }
1096
1116
  } catch ( error ) {
1117
+ // console.log( error );
1097
1118
  logger.error( { error: error, function: 'storeFilter' } );
1098
1119
  return res.sendError( error, 500 );
1099
1120
  }
@@ -17,7 +17,7 @@ import { findOneGroup } from '../services/group.service.js';
17
17
  import { findinfraReason } from '../services/infraReason.service.js';
18
18
  import { findOneUser } from '../services/user.service.js';
19
19
  import xl from 'excel4node';
20
-
20
+ import { findOneinfraReason } from '../services/infraReason.service.js';
21
21
  export async function migrateClient() {
22
22
  try {
23
23
  let oldclient = [];
@@ -697,7 +697,7 @@ export async function camAngleChangeReport( req, res ) {
697
697
  content: buffer,
698
698
  contentType: 'application/xlsx', // e.g., 'application/pdf'
699
699
  };
700
- let subject =`Camera Angle Modified - ${formattedPreviousDay}`;
700
+ let subject = `Camera Angle Modified - ${formattedPreviousDay}`;
701
701
  let html = `<div>We wanted to inform you that the camera angle in your stores has been adjusted recently.</div>`;
702
702
  let result = await sendEmailWithSES( req.body.toMail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
703
703
  if ( result ) {
@@ -737,3 +737,329 @@ export async function download( data ) {
737
737
  }
738
738
  return await wb.writeToBuffer();
739
739
  }
740
+ export async function edgeApplogsCheck( req, res ) {
741
+ try {
742
+ let finalresult= [];
743
+ let ticketList = await findTangoTicket( { 'issueDate': new Date( req.body.issueDate ), 'status': { $ne: 'closed' }, 'ticketDetails.issueStatus': 'notidentified', 'issueType': 'infra' } );
744
+ for ( let ticket of ticketList ) {
745
+ req.body.date = dayjs( ticket.createdAt ).format( 'YYYY-MM-DD' );
746
+ let errorLog = {
747
+ 'size': 500,
748
+ 'query': {
749
+ 'bool': {
750
+ 'must': [
751
+ {
752
+ 'range': {
753
+ 'log_code': {
754
+ 'gte': 1000,
755
+ },
756
+ },
757
+ },
758
+ {
759
+ 'term': {
760
+ 'store_date.keyword': dayjs( ticket.createdAt ).format( 'DD-MM-YYYY' ),
761
+ },
762
+ },
763
+ {
764
+ 'term': {
765
+ 'storeId.keyword': ticket.basicDetails.storeId,
766
+ },
767
+ },
768
+
769
+ ],
770
+
771
+ },
772
+ },
773
+ 'sort': [
774
+ { 'timestamp': { 'order': 'desc' } },
775
+ ],
776
+ };
777
+ const errorLogList = await getOpenSearchData( 'edgeapp_systemlogs', errorLog );
778
+
779
+ let result = [];
780
+
781
+ for ( let error of errorLogList.body.hits.hits ) {
782
+ if ( error._source.log_code == '1003' ) {
783
+ let logCheck = {
784
+ code: error._source.log_code,
785
+ edgelog: error._source.data,
786
+ };
787
+ result.push( logCheck );
788
+ }
789
+ // if ( error._source.log_code == '1001' ) {
790
+ // let logCheck = {
791
+ // code: error._source.log_code,
792
+ // edgelog: error._source.data,
793
+ // };
794
+ // result.push( logCheck );
795
+ // }
796
+
797
+ // if ( error._source.log_code == '1004' ) {
798
+ // let logCheck = {
799
+ // code: error._source.log_code,
800
+ // edgelog: error._source.data,
801
+
802
+ // };
803
+ // result.push( logCheck );
804
+ // }
805
+ if ( error._source.log_code == '1005' ) {
806
+ const bytes = error._source.data.upload_Speed.split( '.' )[0];
807
+ const megabytes = bytesToMB( bytes );
808
+ if ( megabytes < 2 ) {
809
+ let logCheck = {
810
+ code: error._source.log_code,
811
+ edgelog: error._source.data,
812
+
813
+ };
814
+ result.push( logCheck );
815
+ }
816
+ }
817
+
818
+
819
+ if ( error._source.log_code == '1011' ) {
820
+ let logCheck = {
821
+ code: error._source.log_code,
822
+ edgelog: error._source.data,
823
+
824
+ };
825
+ result.push( logCheck );
826
+ }
827
+ if ( error._source.log_code == '1022' ) {
828
+ let logCheck = {
829
+ code: error._source.log_code,
830
+ edgelog: error._source.data,
831
+
832
+ };
833
+ result.push( logCheck );
834
+ }
835
+ if ( error._source.log_code == '1024' ) {
836
+ let logCheck = {
837
+ code: error._source.log_code,
838
+ edgelog: error._source.data,
839
+
840
+ };
841
+ result.push( logCheck );
842
+ }
843
+ if ( error._source.log_code == '1025' ) {
844
+ let logCheck = {
845
+ code: error._source.log_code,
846
+ edgelog: error._source.data,
847
+
848
+ };
849
+ result.push( logCheck );
850
+ }
851
+
852
+ if ( error._source.log_code == '1000' ) {
853
+ let logCheck = {
854
+ code: error._source.log_code,
855
+ edgelog: error._source.data,
856
+
857
+ };
858
+ result.push( logCheck );
859
+ }
860
+
861
+ if ( error._source.log_code == '1007' ) {
862
+ let logCheck = {
863
+ code: error._source.log_code,
864
+ edgelog: error._source.data,
865
+
866
+ };
867
+ result.push( logCheck );
868
+ }
869
+ if ( error._source.log_code == '1034' ) {
870
+ let logCheck = {
871
+ code: error._source.log_code,
872
+ edgelog: error._source.data,
873
+
874
+ };
875
+ result.push( logCheck );
876
+ }
877
+
878
+ if ( Number( error._source.log_code ) > 2000 ) {
879
+ let logCheck = {
880
+ code: error._source.log_code,
881
+ edgelog: error._source.data,
882
+ };
883
+ result.push( logCheck );
884
+ }
885
+ }
886
+ let findissueEdgeApp = {};
887
+ if ( result.length>0 ) {
888
+ for ( let findissue of result ) {
889
+ // console.log( ticket.ticketId );
890
+ const istTimestamp = dayjs.utc( ticket.createdAt ).tz( 'Asia/Kolkata' ).format( 'HH:mm:ss' );
891
+
892
+ if ( findissue.code == '1003' ) {
893
+ // Compare the times
894
+ const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
895
+ const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
896
+ const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
897
+ if ( isOccurringTimeEarlier ) {
898
+ findissueEdgeApp = {
899
+ ticketId: ticket.ticketId,
900
+ edgelog: findissue,
901
+ storeId: ticket.basicDetails.storeId,
902
+ primary: 'System Issues',
903
+ secondary: [ 'Malware or Viruses' ],
904
+ };
905
+ updateIssue( findissueEdgeApp );
906
+ finalresult.push( findissueEdgeApp );
907
+ // console.log( findissueEdgeApp );
908
+ }
909
+ } else if ( findissue.code == '1024' ) {
910
+ const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.data.occuringTime}` );
911
+ const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
912
+ const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
913
+
914
+ const existsInArray = finalresult.some( ( item ) =>
915
+ item.ticketId === ticket.ticketId,
916
+ );
917
+ if ( isOccurringTimeEarlier&&!existsInArray ) {
918
+ findissueEdgeApp = {
919
+ ticketId: ticket.ticketId,
920
+ storeId: ticket.basicDetails.storeId,
921
+ edgelog: findissue.edgelog.data,
922
+ primary: 'Camera Issues',
923
+ secondary: [ 'Camera Not working/RTSP port not working' ],
924
+ };
925
+ updateIssue( findissueEdgeApp );
926
+ finalresult.push( findissueEdgeApp );
927
+ }
928
+ } else if ( findissue.code == '1011' ) {
929
+ const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
930
+ const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
931
+ const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
932
+
933
+ if ( isOccurringTimeEarlier ) {
934
+ findissueEdgeApp = {
935
+ ticketId: ticket.ticketId,
936
+ edgelog: findissue,
937
+ storeId: ticket.basicDetails.storeId,
938
+ primary: 'System Issues',
939
+ secondary: [ 'System is in Sleep Mode' ],
940
+ };
941
+ updateIssue( findissueEdgeApp );
942
+ finalresult.push( findissueEdgeApp );
943
+ // console.log( findissueEdgeApp );
944
+ }
945
+ } else if ( findissue.code ==='1005' ) {
946
+ const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
947
+ const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
948
+ const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
949
+ if ( isOccurringTimeEarlier ) {
950
+ findissueEdgeApp = {
951
+ ticketId: ticket.ticketId,
952
+ edgelog: findissue,
953
+ storeId: ticket.basicDetails.storeId,
954
+ primary: 'Internet Issues',
955
+ secondary: [ 'Slow Internet Speed' ],
956
+ };
957
+ updateIssue( findissueEdgeApp );
958
+ finalresult.push( findissueEdgeApp );
959
+ // console.log( findissueEdgeApp );
960
+ }
961
+ }
962
+ }
963
+ }
964
+ }
965
+ res.sendSuccess( { count: finalresult.length, result: finalresult } );
966
+ } catch ( error ) {
967
+ logger.error( { error: error, function: 'camAngleChangeList' } );
968
+ res.sendError( error, 500 );
969
+ }
970
+ }
971
+ function bytesToMB( bytes ) {
972
+ return bytes / ( 1024 * 1024 );
973
+ }
974
+
975
+ export async function updateIssue( data ) {
976
+ try {
977
+ let Ticket = await findOneTangoTicket(
978
+ {
979
+ ticketId: data.ticketId,
980
+ },
981
+ );
982
+
983
+ data.issueType = Ticket.issueType;
984
+ data.basicDetails = Ticket.basicDetails;
985
+ data.ticketDetails = Ticket.ticketDetails;
986
+ data.ticketActivity = Ticket.ticketActivity;
987
+ if ( data.primary && data.secondary && data.secondary.length ) {
988
+ let primaryReason = await findOneinfraReason( { name: data.primary } );
989
+ if ( !primaryReason ) {
990
+ return res.sendError( 'Primary Reason Not exists in database', 500 );
991
+ }
992
+ const secondary = [];
993
+ const steptoReslove = [];
994
+ for ( let i = 0; i < data.secondary.length; i++ ) {
995
+ let secondaryReason = await findOneinfraReason( { name: data.secondary[i] } );
996
+ if ( !secondaryReason ) {
997
+ return res.sendError( `secondary Reason - ${data.secondary[i]} Not exists in database`, 500 );
998
+ }
999
+ secondary.push( {
1000
+ name: secondaryReason.name,
1001
+ } );
1002
+ let resolveSteps = [];
1003
+ for ( let i = 0; i < secondaryReason.stepstoResolve.length; i++ ) {
1004
+ resolveSteps.push( {
1005
+ name: secondaryReason.stepstoResolve[i].name,
1006
+ } );
1007
+ }
1008
+ steptoReslove.push( {
1009
+ primaryIssue: secondaryReason.name,
1010
+ secondaryIsssue: [ ...resolveSteps ],
1011
+ } );
1012
+ }
1013
+
1014
+ data.ticketActivity.push( {
1015
+ actionType: 'issueUpdate',
1016
+ actionBy: 'automated',
1017
+ IdentifiedBy: 'Tango',
1018
+ timeStamp: new Date(),
1019
+ reasons: [ {
1020
+ primaryIssue: primaryReason.name,
1021
+ secondaryIssue: secondary,
1022
+ } ],
1023
+ },
1024
+ );
1025
+ } else {
1026
+ if ( data.primary == 'Application Issues' ) {
1027
+ data.ticketActivity.push( {
1028
+ actionType: 'issueUpdate',
1029
+ actionBy: 'automated',
1030
+ timeStamp: new Date(),
1031
+ IdentifiedBy: 'Tango',
1032
+ reasons: [ {
1033
+ primaryIssue: data.primary,
1034
+ secondaryIssue: [],
1035
+ } ],
1036
+ },
1037
+ );
1038
+ }
1039
+ }
1040
+ if ( data.issueType == 'infra' ) {
1041
+ let client = await findOneClient( { clientId: data.basicDetails.clientId }, { ticketConfigs: 1 } );
1042
+ let statusCheckAlertTime = dayjs().add( client.ticketConfigs.statusCheckAlert, 'hours' ).format( 'YYYY-MM-DD hh:mm' );
1043
+ data.ticketActivity.push( {
1044
+ actionType: 'statusCheck',
1045
+ timeStamp: statusCheckAlertTime,
1046
+ actionBy: 'Tango',
1047
+ IdentifiedBy: 'Tango',
1048
+ timeStamp: new Date(),
1049
+ statusCheckAlertTime: statusCheckAlertTime,
1050
+ } );
1051
+ }
1052
+ let query = {
1053
+ 'ticketActivity': data.ticketActivity,
1054
+ 'ticketDetails.issueIdentifiedDate': new Date(),
1055
+ 'ticketDetails.issueStatus': 'identified',
1056
+ 'status': 'inprogress',
1057
+ };
1058
+ await updateOneTangoTicket( { ticketId: data.ticketId }, query );
1059
+ // console.log( data );
1060
+ } catch ( error ) {
1061
+ logger.error( { error: error, function: 'updateAutomaticIssue' } );
1062
+ res.sendError( error, 500 );
1063
+ }
1064
+ }
1065
+
@@ -330,6 +330,7 @@ export async function edgeAppLogTable( req, res ) {
330
330
  };
331
331
  const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
332
332
  let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
333
+ // console.log( obj.hour, streamwiseDowntime );
333
334
  if ( streamwiseDowntime.length > 0 ) {
334
335
  const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
335
336
  return accumulator + currentValue.down_time;
@@ -68,6 +68,6 @@ infraRouter.post( '/assignTicket', isAllowedSessionHandler, authorize( {
68
68
  { featureName: 'manage', name: 'tickets', permissions: [ 'isEdit', 'isView' ] } ],
69
69
  } ), assignTicket );
70
70
  infraRouter.post( '/storeFilter', isAllowedSessionHandler, authorize( {
71
- userType: [ 'tango' ], access: [
71
+ userType: [ 'client', 'tango' ], access: [
72
72
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
73
73
  } ), storeFilter );
@@ -2,7 +2,7 @@
2
2
  import express from 'express';
3
3
  import {
4
4
  migrateClient, migrateStores, basicList, clientList, setTicketTime, downStoresList,
5
- openTicketList, assigntoUser, updateRefreshTicket, closeTicket, camAngleChangeReport, spocmailchange, emailUserList, infraReportSent,
5
+ openTicketList, assigntoUser, updateRefreshTicket, closeTicket, edgeApplogsCheck, camAngleChangeReport, spocmailchange, emailUserList, infraReportSent,
6
6
  } from '../controllers/internalInfra.controller.js';
7
7
 
8
8
  export const internalInfraRouter = express.Router();
@@ -21,5 +21,6 @@ internalInfraRouter.get( '/emailUserList', emailUserList );
21
21
  internalInfraRouter.post( '/infraReportSent', infraReportSent );
22
22
  internalInfraRouter.post( '/spocmailchange', spocmailchange );
23
23
  internalInfraRouter.post( '/camAngleChangeReport', camAngleChangeReport );
24
+ internalInfraRouter.post( '/edgeApplogsCheck', edgeApplogsCheck );
24
25
 
25
26