tango-app-api-infra 3.0.63-dev → 3.0.65-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.
@@ -9,7 +9,7 @@ import { join } from 'path';
9
9
  import handlebars from 'handlebars';
10
10
  dayjs.extend( utc );
11
11
  dayjs.extend( timezone );
12
- import { sendEmailWithSES, signedUrl } from 'tango-app-api-middleware';
12
+ import { sendEmailWithSES } from 'tango-app-api-middleware';
13
13
  import { createClient, findClient, aggregateClient, findOneClient } from '../services/client.service.js';
14
14
  import { createStore, findStore, updateOneStore, findOneStore } from '../services/store.service.js';
15
15
  import { findTangoTicket, findOneTangoTicket, countDocumentsTangoTicket, aggregateTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
@@ -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
- import { findOneinfraReason } from '../services/infraReason.service.js';
20
+
21
21
  export async function migrateClient() {
22
22
  try {
23
23
  let oldclient = [];
@@ -86,7 +86,7 @@ export async function clientList( req, res ) {
86
86
  export async function basicList( req, res ) {
87
87
  try {
88
88
  let storeList = await findStore( { status: 'active' },
89
- { 'storeName': 1, 'storeId': 1, 'ticketConfigs': 1, 'clientId': 1, 'storeProfile.open': 1, 'storeProfile.close': 1, 'storeProfile.timeZone': 1 } );
89
+ { 'storeName': 1, 'storeId': 1, 'clientId': 1, 'storeProfile.open': 1, 'storeProfile.close': 1, 'storeProfile.timeZone': 1 } );
90
90
  res.sendSuccess( storeList );
91
91
  } catch ( error ) {
92
92
  logger.error( { error: error, function: 'basicList' } );
@@ -123,7 +123,7 @@ export async function downStoresList( req, res ) {
123
123
  }
124
124
  export async function openTicketList( req, res ) {
125
125
  try {
126
- let openTicketList = await findTangoTicket( { 'issueType': 'infra', 'status': { $ne: 'closed' } }, { issueType: 1, ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
126
+ let openTicketList = await findTangoTicket( { status: { $ne: 'closed' } }, { ticketId: 1, basicDetails: 1, createdAt: 1, updateAt: 1, ticketDetails: 1 } );
127
127
  if ( openTicketList.length ) {
128
128
  res.sendSuccess( {
129
129
  count: openTicketList.length,
@@ -200,11 +200,8 @@ export async function updateRefreshTicket( req, res ) {
200
200
  primaryIssue = Issue[0].reasons[0].primaryIssue;
201
201
  }
202
202
  let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
203
- let getclient = await findOneClient( { clientId: getTicket.basicDetails.clientId } );
204
203
  const html = htmlContent( { ...getTicket, Uidomain: Uidomain, primary: primaryIssue, storeName: getTicket.basicDetails.storeName, hibernation: '', spocName: spocName, date: dayjs( getTicket.issueDate ).format( 'YYYY-MM-DD' ), downtimetotal: downtimetotal, Timestamp: Timestamp, domain: appConfig.url.apiDomain } );
205
- if ( getclient.ticketConfigs.emailAlert && spocEmail && isValidEmail( spocEmail ) ) {
206
- await sendEmailWithSES( spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
207
- }
204
+ await sendEmailWithSES( spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
208
205
  }
209
206
  }
210
207
 
@@ -218,77 +215,71 @@ export async function closeTicket( req, res ) {
218
215
  try {
219
216
  for ( let ticket of req.body.TicketList ) {
220
217
  let getTicket = await findOneTangoTicket( { ticketId: ticket.ticketId } );
221
- if ( getTicket ) {
222
- if ( ticket.status == 'closed' ) {
223
- getTicket.ticketActivity.push( {
224
- actionType: 'dataRecived',
225
- timeStamp: new Date(),
226
- actionBy: 'Tango',
227
- } );
228
- }
229
- await updateOneTangoTicket( { ticketId: ticket.ticketId },
230
- {
231
- status: ticket.status,
232
- ticketActivity: getTicket.ticketActivity,
233
- issueClosedDate: new Date(),
234
- },
235
- );
236
- let downTimeQuery = {
237
- 'size': 1,
238
- 'query': {
239
- 'bool': {
240
- 'must': [
241
- {
242
- 'term': {
243
- 'doc.date.keyword': dayjs( getTicket.issueDate ).format( 'DD-MM-YYYY' ),
244
- },
218
+ if ( ticket.status == 'closed' ) {
219
+ getTicket.ticketActivity.push( {
220
+ actionType: 'dataRecived',
221
+ actionBy: 'Tango',
222
+ } );
223
+ }
224
+ await updateOneTangoTicket( { ticketId: ticket.ticketId },
225
+ {
226
+ status: ticket.status,
227
+ ticketActivity: getTicket.ticketActivity,
228
+ issueClosedDate: new Date(),
229
+ },
230
+ );
231
+ let downTimeQuery = {
232
+ 'size': 1,
233
+ 'query': {
234
+ 'bool': {
235
+ 'must': [
236
+ {
237
+ 'term': {
238
+ 'doc.date.keyword': dayjs( getTicket.issueDate ).format( 'DD-MM-YYYY' ),
245
239
  },
246
- {
247
- 'term': {
248
- 'doc.store_id.keyword': getTicket.basicDetails.storeId,
249
- },
240
+ },
241
+ {
242
+ 'term': {
243
+ 'doc.store_id.keyword': getTicket.basicDetails.storeId,
250
244
  },
245
+ },
251
246
 
252
- ],
247
+ ],
253
248
 
254
- },
255
249
  },
256
- };
257
- let downtimetotal;
258
- const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
259
- let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
260
- if ( streamwiseDowntime.length > 0 ) {
261
- const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
262
- return accumulator + currentValue.down_time;
263
- }, 0 );
264
- const average = sum / streamwiseDowntime.length;
265
- downtimetotal = Math.round( average );
266
- } else {
267
- downtimetotal = 0;
268
- }
250
+ },
251
+ };
252
+ let downtimetotal;
253
+ const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
254
+ let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
255
+ if ( streamwiseDowntime.length > 0 ) {
256
+ const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
257
+ return accumulator + currentValue.down_time;
258
+ }, 0 );
259
+ const average = sum / streamwiseDowntime.length;
260
+ downtimetotal = Math.round( average );
261
+ } else {
262
+ downtimetotal = 0;
263
+ }
269
264
 
270
- let Issue = getTicket.ticketActivity.filter( ( a ) => a.actionType == 'issueUpdate' );
271
- let primaryIssue = '';
265
+ let Issue = getTicket.ticketActivity.filter( ( a ) => a.actionType == 'issueUpdate' );
266
+ let primaryIssue = '';
272
267
 
273
- if ( Issue.length > 0 && Issue[0].reasons.length > 0 ) {
274
- primaryIssue = Issue[0].reasons[0].primaryIssue;
275
- }
276
- let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
277
- const attachments = null;
278
- const subject = `Tango Eye - Infra Ticket Closed for ${getTicket.basicDetails.storeName} `;
279
- const fileContent = readFileSync( join() + '/src/hbs/closeTicekt.hbs', 'utf8' );
280
- const htmlContent = handlebars.compile( fileContent );
281
- let store = await findOneStore( { storeId: getTicket.basicDetails.storeId } );
282
- if ( store.spocDetails && store.spocDetails.length > 0 ) {
283
- let spocEmail = store.spocDetails[0].email;
284
- let spocName = store.spocDetails[0].name;
285
- let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
286
- let getclient = await findOneClient( { clientId: getTicket.basicDetails.clientId } );
287
- const html = htmlContent( { ...getTicket, Uidomain: Uidomain, primaryIssue: primaryIssue, storeName: getTicket.basicDetails.storeName, spocName: spocName, date: dayjs( getTicket.issueDate ).format( 'YYYY-MM-DD HH:mm' ), downtimetotal: downtimetotal, Timestamp: Timestamp, domain: appConfig.url.apiDomain } );
288
- if ( getclient.ticketConfigs.emailAlert && spocEmail && isValidEmail( spocEmail ) ) {
289
- await sendEmailWithSES( spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
290
- }
291
- }
268
+ if ( Issue.length > 0 && Issue[0].reasons.length > 0 ) {
269
+ primaryIssue = Issue[0].reasons[0].primaryIssue;
270
+ }
271
+ let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
272
+ const attachments = null;
273
+ const subject = `Tango Eye - Infra Ticket Closed for ${getTicket.basicDetails.storeName} `;
274
+ const fileContent = readFileSync( join() + '/src/hbs/closeTicekt.hbs', 'utf8' );
275
+ const htmlContent = handlebars.compile( fileContent );
276
+ let store = await findOneStore( { storeId: getTicket.basicDetails.storeId } );
277
+ if ( store.spocDetails && store.spocDetails.length > 0 ) {
278
+ let spocEmail = store.spocDetails[0].email;
279
+ let spocName = store.spocDetails[0].name;
280
+ let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
281
+ const html = htmlContent( { ...getTicket, Uidomain: Uidomain, primaryIssue: primaryIssue, storeName: getTicket.basicDetails.storeName, spocName: spocName, date: dayjs( getTicket.issueDate ).format( 'YYYY-MM-DD HH:mm' ), downtimetotal: downtimetotal, Timestamp: Timestamp, domain: appConfig.url.apiDomain } );
282
+ await sendEmailWithSES( spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
292
283
  }
293
284
  }
294
285
 
@@ -298,10 +289,6 @@ export async function closeTicket( req, res ) {
298
289
  res.sendError( error, 500 );
299
290
  }
300
291
  }
301
- function isValidEmail( email ) {
302
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
303
- return emailRegex.test( email );
304
- }
305
292
  export async function emailUserList( req, res ) {
306
293
  try {
307
294
  let clientList = await aggregateClient( [
@@ -446,11 +433,11 @@ export async function emailUserList( req, res ) {
446
433
  export async function infraReportSent( req, res ) {
447
434
  try {
448
435
  let date;
449
- // if ( req.body.type == 'start' ) {
450
- // date = dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
451
- // } else if ( req.body.type == 'end' ) {
452
- date = dayjs().format( 'YYYY-MM-DD' );
453
- // };
436
+ if ( req.body.type == 'start' ) {
437
+ date = dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
438
+ } else if ( req.body.type == 'end' ) {
439
+ date = dayjs().format( 'YYYY-MM-DD' );
440
+ };
454
441
  let query = [ {
455
442
  $match: {
456
443
  $and: [
@@ -527,17 +514,18 @@ export async function infraReportSent( req, res ) {
527
514
  exportdata.push( {
528
515
  'Client ID': element.basicDetails.clientId,
529
516
  'Client Name': element.basicDetails.clientName,
530
- 'Ticket Created Date & Time': dayjs( element.createdAt ).format( 'YYYY-MM-DD HH:mm A' ),
531
- 'Store ID': element.basicDetails.storeId,
532
- 'Store Name': element.basicDetails.storeName,
517
+ 'Created Date & Time': dayjs( element.createdAt ).format( 'YYYY-MM-DD HH:mm A' ),
518
+ 'Store ID': element.basicDetails.clientName,
519
+ 'Store Name': element.basicDetails.clientName,
533
520
  'Issue ': element.primaryIssue,
534
521
  'Secondary Issue': element.secondaryIssue,
522
+ 'Issue Date & Time': dayjs( element.date ).format( 'YYYY-MM-DD' ),
535
523
  'Status ': element.status,
536
524
  'Responded By': clientuser && clientuser.userName ? clientuser.userName : '-',
537
525
  'Resolved By': tangouser && tangouser.userName ? tangouser.userName : '-',
538
- 'Ticket Closed Date & Time': element.issueClosedDate ? dayjs( element.issueClosedDate ).format( 'YYYY-MM-DD HH:mm A' ) : '-',
526
+ 'Closed Date & Time': element.issueClosedDate?dayjs( element.issueClosedDate ).format( 'YYYY-MM-DD HH:mm A' ):'-',
539
527
  'Latest Comment': '',
540
- 'Activity Log': `${appConfig.url.domain+'/manage/stores/infra-ticket?storeId='+element.basicDetails.storeId}`,
528
+ 'Activity Log': '',
541
529
  } );
542
530
  }
543
531
 
@@ -549,7 +537,7 @@ export async function infraReportSent( req, res ) {
549
537
  ],
550
538
  } );
551
539
  let client = await findOneClient( { clientId: req.body.clientId } );
552
- let avgDownTime = client.ticketConfigs.infraDownTime * 60;
540
+ let avgDownTime = client.ticketConfigs.infraDownTime*60;
553
541
  let issueList = await findinfraReason( { parentId: { '$exists': false } } );
554
542
  const categoryCounts = {};
555
543
  let response;
@@ -573,8 +561,8 @@ export async function infraReportSent( req, res ) {
573
561
  } ) );
574
562
  }
575
563
  let reportdate = dayjs().format( 'YYYY-MM-DD' );
576
- let attachments = null;
577
- if ( exportdata.length > 0 ) {
564
+ let attachments= null;
565
+ if ( exportdata.length>0 ) {
578
566
  const wb = new xl.Workbook();
579
567
  const ws = wb.addWorksheet( 'Daily report' );
580
568
  const headers = Object.keys( exportdata[0] );
@@ -606,458 +594,10 @@ export async function infraReportSent( req, res ) {
606
594
 
607
595
 
608
596
  const html = htmlContent( { ...req.body, Uidomain: Uidomain, issueCount: issueCount, avgDownTime: avgDownTime, reportdate: reportdate, content: response, date: date, domain: appConfig.url.apiDomain } );
609
- if ( isValidEmail( req.body.email ) ) {
610
- const result = await sendEmailWithSES( req.body.email, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
611
- res.sendSuccess( result );
612
- }
597
+ const result = await sendEmailWithSES( req.body.email, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
598
+ res.sendSuccess( result );
613
599
  } catch ( error ) {
614
600
  logger.error( { error: error, function: 'infraReportSent' } );
615
601
  res.sendError( error, 500 );
616
602
  }
617
603
  }
618
- export async function spocmailchange() {
619
- let storelist = await findStore( {} );
620
- for ( let store of storelist ) {
621
- if ( store && store.spocDetails ) {
622
- let spoclist = [];
623
- for ( let spoc of store.spocDetails ) {
624
- spoc.email = spoc.email.replace( '@', '1@' ),
625
- spoclist.push( spoc );
626
- }
627
- await updateOneStore( { storeId: store.storeId }, { spocDetails: spoclist } );
628
- }
629
- }
630
- }
631
-
632
-
633
- export async function camAngleChangeReport( req, res ) {
634
- try {
635
- const currentDate = dayjs();
636
-
637
-
638
- const previousDay = currentDate.subtract( 1, 'day' );
639
-
640
-
641
- const formattedPreviousDay = previousDay.format( 'DD-MM-YYYY' );
642
- const angleChange = await getOpenSearchData( 'camera-angle-change',
643
- {
644
- 'query': {
645
- 'bool': {
646
- 'must': [
647
- {
648
- 'term': {
649
- 'date.keyword': formattedPreviousDay,
650
- },
651
- },
652
- {
653
- 'term': {
654
- 'client_id.keyword': req.body.clientId,
655
- },
656
- },
657
- ],
658
- },
659
- },
660
- } );
661
- if ( angleChange.body.hits.hits.length > 0 ) {
662
- const exportdata = [];
663
-
664
- for ( let camera of angleChange.body.hits.hits ) {
665
- let result = camera._source;
666
-
667
- if ( result && result.cameraAngleChangeStatus && result.camera_info.length > 0 ) {
668
- for ( let stream of result.camera_info ) {
669
- let params = {
670
- Bucket: appConfig.cloud.aws.bucket.cameraAngle,
671
- file_path: stream.path,
672
- };
673
- let Image = await signedUrl( params );
674
-
675
-
676
- let findStore = await findOneStore( { storeId: result.store_id } );
677
-
678
-
679
- exportdata.push( {
680
- 'Store Name': findStore.storeName,
681
- 'Store Code': findStore.storeId,
682
- 'Date Changed': formattedPreviousDay,
683
- 'ImageURL': {
684
- url: Image,
685
- label: 'Angle changed Image',
686
- },
687
- } );
688
- }
689
- }
690
- }
691
- let buffer = await download( exportdata );
692
-
693
- let attachments = {
694
- filename: `Camera angle change- ${formattedPreviousDay}.xlsx`,
695
- content: buffer,
696
- contentType: 'application/xlsx', // e.g., 'application/pdf'
697
- };
698
- let subject = `Camera Angle Modified - ${formattedPreviousDay}`;
699
- let html = `<div>We wanted to inform you that the camera angle in your stores has been adjusted recently.</div>`;
700
- let result = await sendEmailWithSES( req.body.toMail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
701
- if ( result ) {
702
- res.sendSuccess( 'Email send successfully' );
703
- }
704
- } else {
705
- res.sendSuccess( 'No changes in camera Angle' );
706
- }
707
- } catch ( error ) {
708
- logger.error( { error: error, function: 'camAngleChangeList' } );
709
- res.sendError( error, 500 );
710
- }
711
- }
712
-
713
-
714
- export async function download( data ) {
715
- const wb = new xl.Workbook();
716
- const ws = wb.addWorksheet( 'Worksheet Name' );
717
- const headers = Object.keys( data[0] );
718
-
719
- for ( let i = 0; i < headers.length; i++ ) {
720
- ws.cell( 1, i + 1 ).string( headers[i] );
721
- };
722
- for ( let i = 0; i < data.length; i++ ) {
723
- const dataRow = data[i];
724
- for ( let j = 0; j < headers.length; j++ ) {
725
- const header = headers[j];
726
- const value = dataRow[header];
727
-
728
- if ( typeof value === 'object' && value.hasOwnProperty( 'label' ) && value.hasOwnProperty( 'url' ) ) {
729
- ws.cell( i + 2, j + 1 ).link( value.url );
730
- ws.cell( i + 2, j + 1 ).string( value.label );
731
- } else {
732
- ws.cell( i + 2, j + 1 ).string( value?.toString() );
733
- }
734
- }
735
- }
736
- return await wb.writeToBuffer();
737
- }
738
- export async function edgeApplogsCheck( req, res ) {
739
- try {
740
- let finalresult= [];
741
- let ticketList = await findTangoTicket( { 'issueDate': new Date( req.body.issueDate ), 'status': { $ne: 'closed' }, 'ticketDetails.issueStatus': 'notidentified', 'issueType': 'infra' } );
742
- for ( let ticket of ticketList ) {
743
- req.body.date = dayjs( ticket.createdAt ).format( 'YYYY-MM-DD' );
744
- let errorLog = {
745
- 'size': 500,
746
- 'query': {
747
- 'bool': {
748
- 'must': [
749
- {
750
- 'range': {
751
- 'log_code': {
752
- 'gte': 1000,
753
- },
754
- },
755
- },
756
- {
757
- 'term': {
758
- 'store_date.keyword': dayjs( ticket.createdAt ).format( 'DD-MM-YYYY' ),
759
- },
760
- },
761
- {
762
- 'term': {
763
- 'storeId.keyword': ticket.basicDetails.storeId,
764
- },
765
- },
766
-
767
- ],
768
-
769
- },
770
- },
771
- 'sort': [
772
- { 'timestamp': { 'order': 'desc' } },
773
- ],
774
- };
775
- const errorLogList = await getOpenSearchData( 'edgeapp_systemlogs', errorLog );
776
-
777
- let result = [];
778
-
779
- for ( let error of errorLogList.body.hits.hits ) {
780
- if ( error._source.log_code == '1003' ) {
781
- let logCheck = {
782
- code: error._source.log_code,
783
- edgelog: error._source.data,
784
- };
785
- result.push( logCheck );
786
- }
787
- // if ( error._source.log_code == '1001' ) {
788
- // let logCheck = {
789
- // code: error._source.log_code,
790
- // edgelog: error._source.data,
791
- // };
792
- // result.push( logCheck );
793
- // }
794
-
795
- // if ( error._source.log_code == '1004' ) {
796
- // let logCheck = {
797
- // code: error._source.log_code,
798
- // edgelog: error._source.data,
799
-
800
- // };
801
- // result.push( logCheck );
802
- // }
803
- if ( error._source.log_code == '1005' ) {
804
- const bytes = error._source.data.upload_Speed.split( '.' )[0];
805
- const megabytes = bytesToMB( bytes );
806
- if ( megabytes < 2 ) {
807
- let logCheck = {
808
- code: error._source.log_code,
809
- edgelog: error._source.data,
810
-
811
- };
812
- result.push( logCheck );
813
- }
814
- }
815
-
816
-
817
- if ( error._source.log_code == '1011' ) {
818
- let logCheck = {
819
- code: error._source.log_code,
820
- edgelog: error._source.data,
821
-
822
- };
823
- result.push( logCheck );
824
- }
825
- if ( error._source.log_code == '1022' ) {
826
- let logCheck = {
827
- code: error._source.log_code,
828
- edgelog: error._source.data,
829
-
830
- };
831
- result.push( logCheck );
832
- }
833
- if ( error._source.log_code == '1024' ) {
834
- let logCheck = {
835
- code: error._source.log_code,
836
- edgelog: error._source.data,
837
-
838
- };
839
- result.push( logCheck );
840
- }
841
- if ( error._source.log_code == '1025' ) {
842
- let logCheck = {
843
- code: error._source.log_code,
844
- edgelog: error._source.data,
845
-
846
- };
847
- result.push( logCheck );
848
- }
849
-
850
- if ( error._source.log_code == '1000' ) {
851
- let logCheck = {
852
- code: error._source.log_code,
853
- edgelog: error._source.data,
854
-
855
- };
856
- result.push( logCheck );
857
- }
858
-
859
- if ( error._source.log_code == '1007' ) {
860
- let logCheck = {
861
- code: error._source.log_code,
862
- edgelog: error._source.data,
863
-
864
- };
865
- result.push( logCheck );
866
- }
867
- if ( error._source.log_code == '1034' ) {
868
- let logCheck = {
869
- code: error._source.log_code,
870
- edgelog: error._source.data,
871
-
872
- };
873
- result.push( logCheck );
874
- }
875
-
876
- if ( Number( error._source.log_code ) > 2000 ) {
877
- let logCheck = {
878
- code: error._source.log_code,
879
- edgelog: error._source.data,
880
- };
881
- result.push( logCheck );
882
- }
883
- }
884
- let findissueEdgeApp = {};
885
- if ( result.length>0 ) {
886
- for ( let findissue of result ) {
887
- // console.log( ticket.ticketId );
888
- const istTimestamp = dayjs.utc( ticket.createdAt ).tz( 'Asia/Kolkata' ).format( 'HH:mm:ss' );
889
-
890
- if ( findissue.code == '1003' ) {
891
- // Compare the times
892
- const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
893
- const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
894
- const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
895
- if ( isOccurringTimeEarlier ) {
896
- findissueEdgeApp = {
897
- ticketId: ticket.ticketId,
898
- edgelog: findissue,
899
- storeId: ticket.basicDetails.storeId,
900
- primary: 'System Issues',
901
- secondary: [ 'Malware or Viruses' ],
902
- };
903
- updateIssue( findissueEdgeApp );
904
- finalresult.push( findissueEdgeApp );
905
- // console.log( findissueEdgeApp );
906
- }
907
- } else if ( findissue.code == '1024' ) {
908
- const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.data.occuringTime}` );
909
- const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
910
- const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
911
-
912
- const existsInArray = finalresult.some( ( item ) =>
913
- item.ticketId === ticket.ticketId,
914
- );
915
- if ( isOccurringTimeEarlier&&!existsInArray ) {
916
- findissueEdgeApp = {
917
- ticketId: ticket.ticketId,
918
- storeId: ticket.basicDetails.storeId,
919
- edgelog: findissue.edgelog.data,
920
- primary: 'Camera Issues',
921
- secondary: [ 'Camera Not working/RTSP port not working' ],
922
- };
923
- updateIssue( findissueEdgeApp );
924
- finalresult.push( findissueEdgeApp );
925
- }
926
- } else if ( findissue.code == '1011' ) {
927
- const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
928
- const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
929
- const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
930
-
931
- if ( isOccurringTimeEarlier ) {
932
- findissueEdgeApp = {
933
- ticketId: ticket.ticketId,
934
- edgelog: findissue,
935
- storeId: ticket.basicDetails.storeId,
936
- primary: 'System Issues',
937
- secondary: [ 'System is in Sleep Mode' ],
938
- };
939
- updateIssue( findissueEdgeApp );
940
- finalresult.push( findissueEdgeApp );
941
- // console.log( findissueEdgeApp );
942
- }
943
- } else if ( findissue.code ==='1005' ) {
944
- const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
945
- const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
946
- const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
947
- if ( isOccurringTimeEarlier ) {
948
- findissueEdgeApp = {
949
- ticketId: ticket.ticketId,
950
- edgelog: findissue,
951
- storeId: ticket.basicDetails.storeId,
952
- primary: 'Internet Issues',
953
- secondary: [ 'Slow Internet Speed' ],
954
- };
955
- updateIssue( findissueEdgeApp );
956
- finalresult.push( findissueEdgeApp );
957
- // console.log( findissueEdgeApp );
958
- }
959
- }
960
- }
961
- }
962
- }
963
- res.sendSuccess( { count: finalresult.length, result: finalresult } );
964
- } catch ( error ) {
965
- logger.error( { error: error, function: 'camAngleChangeList' } );
966
- res.sendError( error, 500 );
967
- }
968
- }
969
- function bytesToMB( bytes ) {
970
- return bytes / ( 1024 * 1024 );
971
- }
972
-
973
- export async function updateIssue( data ) {
974
- try {
975
- let Ticket = await findOneTangoTicket(
976
- {
977
- ticketId: data.ticketId,
978
- },
979
- );
980
-
981
- data.issueType = Ticket.issueType;
982
- data.basicDetails = Ticket.basicDetails;
983
- data.ticketDetails = Ticket.ticketDetails;
984
- data.ticketActivity = Ticket.ticketActivity;
985
- if ( data.primary && data.secondary && data.secondary.length ) {
986
- let primaryReason = await findOneinfraReason( { name: data.primary } );
987
- if ( !primaryReason ) {
988
- return res.sendError( 'Primary Reason Not exists in database', 500 );
989
- }
990
- const secondary = [];
991
- const steptoReslove = [];
992
- for ( let i = 0; i < data.secondary.length; i++ ) {
993
- let secondaryReason = await findOneinfraReason( { name: data.secondary[i] } );
994
- if ( !secondaryReason ) {
995
- return res.sendError( `secondary Reason - ${data.secondary[i]} Not exists in database`, 500 );
996
- }
997
- secondary.push( {
998
- name: secondaryReason.name,
999
- } );
1000
- let resolveSteps = [];
1001
- for ( let i = 0; i < secondaryReason.stepstoResolve.length; i++ ) {
1002
- resolveSteps.push( {
1003
- name: secondaryReason.stepstoResolve[i].name,
1004
- } );
1005
- }
1006
- steptoReslove.push( {
1007
- primaryIssue: secondaryReason.name,
1008
- secondaryIsssue: [ ...resolveSteps ],
1009
- } );
1010
- }
1011
-
1012
- data.ticketActivity.push( {
1013
- actionType: 'issueUpdate',
1014
- actionBy: 'automated',
1015
- IdentifiedBy: 'Tango',
1016
- timeStamp: new Date(),
1017
- reasons: [ {
1018
- primaryIssue: primaryReason.name,
1019
- secondaryIssue: secondary,
1020
- } ],
1021
- },
1022
- );
1023
- } else {
1024
- if ( data.primary == 'Application Issues' ) {
1025
- data.ticketActivity.push( {
1026
- actionType: 'issueUpdate',
1027
- actionBy: 'automated',
1028
- timeStamp: new Date(),
1029
- IdentifiedBy: 'Tango',
1030
- reasons: [ {
1031
- primaryIssue: data.primary,
1032
- secondaryIssue: [],
1033
- } ],
1034
- },
1035
- );
1036
- }
1037
- }
1038
- if ( data.issueType == 'infra' ) {
1039
- let client = await findOneClient( { clientId: data.basicDetails.clientId }, { ticketConfigs: 1 } );
1040
- let statusCheckAlertTime = dayjs().add( client.ticketConfigs.statusCheckAlert, 'hours' ).format( 'YYYY-MM-DD hh:mm' );
1041
- data.ticketActivity.push( {
1042
- actionType: 'statusCheck',
1043
- timeStamp: statusCheckAlertTime,
1044
- actionBy: 'Tango',
1045
- IdentifiedBy: 'Tango',
1046
- timeStamp: new Date(),
1047
- statusCheckAlertTime: statusCheckAlertTime,
1048
- } );
1049
- }
1050
- let query = {
1051
- 'ticketActivity': data.ticketActivity,
1052
- 'ticketDetails.issueIdentifiedDate': new Date(),
1053
- 'ticketDetails.issueStatus': 'identified',
1054
- 'status': 'inprogress',
1055
- };
1056
- await updateOneTangoTicket( { ticketId: data.ticketId }, query );
1057
- // console.log( data );
1058
- } catch ( error ) {
1059
- logger.error( { error: error, function: 'updateAutomaticIssue' } );
1060
- res.sendError( error, 500 );
1061
- }
1062
- }
1063
-