tango-app-api-infra 3.0.63-dev → 3.0.64-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.63-dev",
3
+ "version": "3.0.64-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -125,33 +125,28 @@ export async function bulkcreateTicket( req, res ) {
125
125
 
126
126
  export async function updateStatus( req, res ) {
127
127
  try {
128
- console.log( req.user.userType );
129
128
  if ( req.user.userType == 'tango' ) {
130
- if ( req.body.status == 'inprogress' ) {
131
- req.body.ticketActivity.push( {
132
- actionType: 'statusChange',
133
- timeStamp: new Date(),
134
- actionBy: 'Tango',
135
- IdentifiedBy: req.user.userName,
136
- } );
137
- req.body.status ='inprogress';
138
- }
129
+ req.body.ticketActivity.push( {
130
+ actionType: 'statusChange',
131
+ timeStamp: new Date(),
132
+ actionBy: 'Tango',
133
+ IdentifiedBy: req.user.userName,
134
+ } );
135
+ req.body.status = 'inprogress';
139
136
  req.body.ticketDetails.addressingUser = req.user._id;
140
- console.log( req.body );
141
137
  let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, req.body );
142
138
  if ( updateTicket ) {
143
139
  res.sendSuccess( 'Ticket Updated Successfully' );
144
140
  }
145
141
  } else if ( req.user.userType == 'client' ) {
146
- if ( req.body.status == 'inprogress' ) {
147
- req.body.ticketActivity.push( {
148
- actionType: 'statusChange',
149
- timeStamp: new Date(),
150
- actionBy: 'User',
151
- IdentifiedBy: req.user.userName,
152
- } );
153
- req.body.status ='inprogress';
154
- }
142
+ req.body.ticketActivity.push( {
143
+ actionType: 'statusChange',
144
+ timeStamp: new Date(),
145
+ actionBy: 'User',
146
+ IdentifiedBy: req.user.userName,
147
+ } );
148
+ req.body.status = 'inprogress';
149
+
155
150
  req.body.ticketDetails.addressingClient = req.user._id;
156
151
  let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, req.body );
157
152
  if ( updateTicket ) {
@@ -1280,13 +1275,12 @@ export async function storeFilter( req, res ) {
1280
1275
  const uniqueStoreIds = [ ...new Set( stores.map( ( store ) => store.basicDetails.storeId ) ) ];
1281
1276
  const uniqueStoreObjects = uniqueStoreIds.map( ( storeId ) => ( { 'storeId': storeId } ) );
1282
1277
 
1283
- if ( uniqueStoreObjects.length>0 ) {
1278
+ if ( uniqueStoreObjects.length > 0 ) {
1284
1279
  res.sendSuccess( { count: uniqueStoreObjects.length, data: uniqueStoreObjects } );
1285
1280
  } else {
1286
1281
  res.sendError( 'No data', 204 );
1287
1282
  }
1288
1283
  } catch ( error ) {
1289
- // console.log( error );
1290
1284
  logger.error( { error: error, function: 'storeFilter' } );
1291
1285
  return res.sendError( error, 500 );
1292
1286
  }
@@ -468,6 +468,13 @@ export async function infraReportSent( req, res ) {
468
468
  status: 1,
469
469
  ticketDetails: 1,
470
470
  issueClosedDate: 1,
471
+ otherscomment: {
472
+ $filter: {
473
+ input: '$ticketActivity',
474
+ as: 'item',
475
+ cond: { $eq: [ '$$item.actionType', 'comment' ] },
476
+ },
477
+ },
471
478
  primaryIssue: {
472
479
  $filter: {
473
480
  input: '$ticketActivity',
@@ -477,6 +484,11 @@ export async function infraReportSent( req, res ) {
477
484
  },
478
485
  },
479
486
  },
487
+ {
488
+ $unwind: {
489
+ path: '$otherscomment', preserveNullAndEmptyArrays: true,
490
+ },
491
+ },
480
492
  {
481
493
  $unwind: {
482
494
  path: '$primaryIssue', preserveNullAndEmptyArrays: true,
@@ -500,6 +512,8 @@ export async function infraReportSent( req, res ) {
500
512
  status: 1,
501
513
  ticketDetails: 1,
502
514
  issueClosedDate: 1,
515
+ ommentText: { $ifNull: [ '$primaryIssue.comment', '-' ] },
516
+ otherscomment: { $ifNull: [ '$otherscomment.comment', '-' ] },
503
517
  primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
504
518
  secondaryIssue: { $ifNull: [ '$primaryIssue.reasons.secondaryIssue.name', '-' ] },
505
519
  },
@@ -510,11 +524,12 @@ export async function infraReportSent( req, res ) {
510
524
  ticketDetails: { $first: '$ticketDetails' },
511
525
  issueClosedDate: { $first: '$issueClosedDate' },
512
526
  basicDetails: { $first: '$basicDetails' },
527
+ commentText: { $last: '$commentText' },
513
528
  primaryIssue: { $last: '$primaryIssue' },
514
529
  secondaryIssue: { $last: '$secondaryIssue' },
530
+ otherscomment: { $last: '$otherscomment' },
515
531
  createdAt: { $first: '$createdAt' },
516
532
  status: { $last: '$status' },
517
-
518
533
  },
519
534
  },
520
535
  ];
@@ -527,7 +542,7 @@ export async function infraReportSent( req, res ) {
527
542
  exportdata.push( {
528
543
  'Client ID': element.basicDetails.clientId,
529
544
  'Client Name': element.basicDetails.clientName,
530
- 'Ticket Created Date & Time': dayjs( element.createdAt ).format( 'YYYY-MM-DD HH:mm A' ),
545
+ 'Ticket Created Date & Time': dayjs( element.createdAt ).tz( 'Asia/Kolkata' ).format( 'YYYY-MM-DD HH:mm A' ),
531
546
  'Store ID': element.basicDetails.storeId,
532
547
  'Store Name': element.basicDetails.storeName,
533
548
  'Issue ': element.primaryIssue,
@@ -535,9 +550,12 @@ export async function infraReportSent( req, res ) {
535
550
  'Status ': element.status,
536
551
  'Responded By': clientuser && clientuser.userName ? clientuser.userName : '-',
537
552
  'Resolved By': tangouser && tangouser.userName ? tangouser.userName : '-',
538
- 'Ticket Closed Date & Time': element.issueClosedDate ? dayjs( element.issueClosedDate ).format( 'YYYY-MM-DD HH:mm A' ) : '-',
539
- 'Latest Comment': '',
540
- 'Activity Log': `${appConfig.url.domain+'/manage/stores/infra-ticket?storeId='+element.basicDetails.storeId}`,
553
+ 'Ticket Closed Date & Time': element.issueClosedDate ? dayjs( element.issueClosedDate ).tz( 'Asia/Kolkata' ).format( 'YYYY-MM-DD HH:mm A' ) : '-',
554
+ 'Latest Comment': element.otherscomment?element.otherscomment:element.commentText,
555
+ 'Activity Log': {
556
+ label: 'Link',
557
+ url: `${appConfig.url.domain+'/manage/stores/infra-ticket?storeId='+element.basicDetails.storeId}`,
558
+ },
541
559
  } );
542
560
  }
543
561
 
@@ -574,30 +592,13 @@ export async function infraReportSent( req, res ) {
574
592
  }
575
593
  let reportdate = dayjs().format( 'YYYY-MM-DD' );
576
594
  let attachments = null;
577
- if ( exportdata.length > 0 ) {
578
- const wb = new xl.Workbook();
579
- const ws = wb.addWorksheet( 'Daily report' );
580
- const headers = Object.keys( exportdata[0] );
581
-
582
- for ( let i = 0; i < headers.length; i++ ) {
583
- ws.cell( 1, i + 1 ).string( headers[i] );
584
- };
585
- for ( let i = 0; i < exportdata.length; i++ ) {
586
- const dataRow = exportdata[i];
587
- for ( let j = 0; j < headers.length; j++ ) {
588
- const header = headers[j];
589
- const value = dataRow[header];
590
- ws.cell( i + 2, j + 1 ).string( value?.toString() );
591
- }
592
- }
593
- let buffer = await wb.writeToBuffer();
595
+ let buffer = await download( exportdata );
596
+ attachments = {
597
+ filename: `dailyInfraReport- ${reportdate}.xlsx`,
598
+ content: buffer,
599
+ contentType: 'application/xlsx', // e.g., 'application/pdf'
600
+ };
594
601
 
595
- attachments = {
596
- filename: `dailyInfraReport- ${reportdate}.xlsx`,
597
- content: buffer,
598
- contentType: 'application/xlsx', // e.g., 'application/pdf'
599
- };
600
- }
601
602
 
602
603
  const subject = `Daily Digest - Infra Downtime Report - ${reportdate}`;
603
604
  const fileContent = readFileSync( join() + '/src/hbs/dailyInfraReport.hbs', 'utf8' );
@@ -724,8 +725,7 @@ export async function download( data ) {
724
725
  for ( let j = 0; j < headers.length; j++ ) {
725
726
  const header = headers[j];
726
727
  const value = dataRow[header];
727
-
728
- if ( typeof value === 'object' && value.hasOwnProperty( 'label' ) && value.hasOwnProperty( 'url' ) ) {
728
+ if ( value&& typeof value === 'object' && value.hasOwnProperty( 'label' ) && value.hasOwnProperty( 'url' ) ) {
729
729
  ws.cell( i + 2, j + 1 ).link( value.url );
730
730
  ws.cell( i + 2, j + 1 ).string( value.label );
731
731
  } else {
@@ -884,11 +884,9 @@ export async function edgeApplogsCheck( req, res ) {
884
884
  let findissueEdgeApp = {};
885
885
  if ( result.length>0 ) {
886
886
  for ( let findissue of result ) {
887
- // console.log( ticket.ticketId );
888
887
  const istTimestamp = dayjs.utc( ticket.createdAt ).tz( 'Asia/Kolkata' ).format( 'HH:mm:ss' );
889
888
 
890
889
  if ( findissue.code == '1003' ) {
891
- // Compare the times
892
890
  const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
893
891
  const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
894
892
  const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
@@ -902,7 +900,6 @@ export async function edgeApplogsCheck( req, res ) {
902
900
  };
903
901
  updateIssue( findissueEdgeApp );
904
902
  finalresult.push( findissueEdgeApp );
905
- // console.log( findissueEdgeApp );
906
903
  }
907
904
  } else if ( findissue.code == '1024' ) {
908
905
  const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.data.occuringTime}` );
@@ -938,7 +935,6 @@ export async function edgeApplogsCheck( req, res ) {
938
935
  };
939
936
  updateIssue( findissueEdgeApp );
940
937
  finalresult.push( findissueEdgeApp );
941
- // console.log( findissueEdgeApp );
942
938
  }
943
939
  } else if ( findissue.code ==='1005' ) {
944
940
  const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
@@ -954,7 +950,6 @@ export async function edgeApplogsCheck( req, res ) {
954
950
  };
955
951
  updateIssue( findissueEdgeApp );
956
952
  finalresult.push( findissueEdgeApp );
957
- // console.log( findissueEdgeApp );
958
953
  }
959
954
  }
960
955
  }
@@ -1054,7 +1049,6 @@ export async function updateIssue( data ) {
1054
1049
  'status': 'inprogress',
1055
1050
  };
1056
1051
  await updateOneTangoTicket( { ticketId: data.ticketId }, query );
1057
- // console.log( data );
1058
1052
  } catch ( error ) {
1059
1053
  logger.error( { error: error, function: 'updateAutomaticIssue' } );
1060
1054
  res.sendError( error, 500 );
@@ -28,7 +28,20 @@ export async function storeTicketList( req, res ) {
28
28
  ticketId: 1,
29
29
  issueStatus: '$ticketDetails.issueStatus',
30
30
  ticketType: '$ticketDetails.ticketType',
31
- comments: { $size: '$ticketActivity' },
31
+ otherscomment: {
32
+ $filter: {
33
+ input: '$ticketActivity',
34
+ as: 'item',
35
+ cond: { $eq: [ '$$item.actionType', 'comment' ] },
36
+ },
37
+ },
38
+ comments: {
39
+ $filter: {
40
+ input: '$ticketActivity',
41
+ as: 'item',
42
+ cond: { $ne: [ '$$item.actionType', 'statusChange' ] },
43
+ },
44
+ },
32
45
  primaryIssue: {
33
46
  $filter: {
34
47
  input: '$ticketActivity',
@@ -43,11 +56,21 @@ export async function storeTicketList( req, res ) {
43
56
  path: '$primaryIssue', preserveNullAndEmptyArrays: true,
44
57
  },
45
58
  },
59
+ {
60
+ $unwind: {
61
+ path: '$otherscomment', preserveNullAndEmptyArrays: true,
62
+ },
63
+ },
46
64
  {
47
65
  $unwind: {
48
66
  path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
49
67
  },
50
68
  },
69
+ {
70
+ $unwind: {
71
+ path: '$primaryIssue.reasons.secondaryIssue', preserveNullAndEmptyArrays: true,
72
+ },
73
+ },
51
74
  {
52
75
  $project: {
53
76
  storeId: 1,
@@ -57,10 +80,12 @@ export async function storeTicketList( req, res ) {
57
80
  ticketId: 1,
58
81
  issueStatus: 1,
59
82
  ticketType: 1,
60
- comments: 1,
83
+ comments: { $size: '$comments' },
61
84
  issueDate: 1,
85
+ commentText: '$primaryIssue.comment',
62
86
  primaryIssue: '$primaryIssue.reasons.primaryIssue',
63
- secondaryIssue: '$primaryIssue.reasons.secondaryIssue',
87
+ secondaryIssue: '$primaryIssue.reasons.secondaryIssue.name',
88
+ otherscomment: '$otherscomment.comment',
64
89
  },
65
90
  },
66
91
  {
@@ -75,8 +100,11 @@ export async function storeTicketList( req, res ) {
75
100
  issueStatus: { $first: '$issueStatus' },
76
101
  ticketType: { $first: '$ticketType' },
77
102
  comments: { $first: '$comments' },
103
+ commentText: { $last: '$commentText' },
78
104
  primaryIssue: { $last: '$primaryIssue' },
79
105
  secondaryIssue: { $last: '$secondaryIssue' },
106
+ otherscomment: { $last: '$otherscomment' },
107
+
80
108
  },
81
109
  },
82
110
  {
@@ -102,8 +130,10 @@ export async function storeTicketList( req, res ) {
102
130
  'TICKET ID': element.ticketId,
103
131
  'DATE': element.Date,
104
132
  'ISSUE CLOSED DATE': element.issueClosedDate,
105
- 'ISSUE': element.primaryIssue,
133
+ 'PRIMARY ISSUE': element.primaryIssue,
134
+ 'SECONDARY ISSUE': element.secondaryIssue,
106
135
  'STATUS': element.status,
136
+ 'COMMENT': element.otherscomment?element.otherscomment:element.commentText,
107
137
  } );
108
138
  } );
109
139
  await download( exportdata, res );
@@ -330,7 +360,6 @@ export async function edgeAppLogTable( req, res ) {
330
360
  };
331
361
  const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
332
362
  let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
333
- // console.log( obj.hour, streamwiseDowntime );
334
363
  if ( streamwiseDowntime.length > 0 ) {
335
364
  const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
336
365
  return accumulator + currentValue.down_time;
@@ -113,6 +113,7 @@ export async function userTicketList( req, res ) {
113
113
  query.push( {
114
114
  $match: {
115
115
  $and: [
116
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
116
117
  { issueType: req.body.issueType },
117
118
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
118
119
  ],
@@ -122,6 +123,7 @@ export async function userTicketList( req, res ) {
122
123
  query.push( {
123
124
  $match: {
124
125
  $and: [
126
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
125
127
  { issueType: { $in: [ 'highcount', 'lowcount' ] } },
126
128
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
127
129
  ],
@@ -334,6 +336,7 @@ export async function workHistory( req, res ) {
334
336
  query.push( {
335
337
  $match: {
336
338
  $and: [
339
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
337
340
  { 'status': 'closed' },
338
341
  { issueType: req.body.issueType },
339
342
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
@@ -344,6 +347,7 @@ export async function workHistory( req, res ) {
344
347
  query.push( {
345
348
  $match: {
346
349
  $and: [
350
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
347
351
  { 'status': 'closed' },
348
352
  { issueType: { $in: [ 'highcount', 'lowcount' ] } },
349
353
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
@@ -443,6 +447,7 @@ export async function workHistory( req, res ) {
443
447
  issueClosedDate: 1,
444
448
  ticketId: 1,
445
449
  issueStatus: 1,
450
+ status: 1,
446
451
  ticketType: 1,
447
452
  infraIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '' ] },
448
453
  },
@@ -202,8 +202,6 @@ export async function validateTicketstatus( req, res, next ) {
202
202
  if ( req.body.status == 'closed' ) {
203
203
  return res.sendSuccess( 'Ticket already closed' );
204
204
  }
205
- console.log( req.body.ticketDetails );
206
-
207
205
  if ( req.body.ticketDetails.ticketType==='firsttimeticket'&&req.body.ticketDetails.issueStatus==='identified' ) {
208
206
  return res.sendSuccess( 'Ticket already Addressed' );
209
207
  }