tango-app-api-infra 3.0.64-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.
- package/app.js +45 -0
- package/index.js +1 -4
- package/package.json +7 -5
- package/src/controllers/clientInfra.controller.js +7 -39
- package/src/controllers/infra.controllers.js +103 -676
- package/src/controllers/internalInfra.controller.js +103 -557
- package/src/controllers/storeInfra.controlller.js +7 -37
- package/src/controllers/userInfra.controller.js +22 -75
- package/src/docs/infra.docs.js +28 -0
- package/src/dtos/infra.dtos.js +12 -0
- package/src/routes/infra.routes.js +8 -25
- package/src/routes/internalInfra.routes.js +1 -4
- package/src/services/tangoTicket.service.js +0 -3
- package/src/validations/infra.validation.js +7 -53
- package/src/controllers/dataMismatch.controller.js +0 -23
- package/src/controllers/employeeTraning.controller.js +0 -50
- package/src/routes/dataMismatch.routes.js +0 -10
- package/src/routes/employeetrainig.routes.js +0 -17
|
@@ -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
|
|
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
|
-
|
|
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, '
|
|
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( {
|
|
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
|
-
|
|
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 (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
'
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
248
|
-
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
271
|
-
|
|
265
|
+
let Issue = getTicket.ticketActivity.filter( ( a ) => a.actionType == 'issueUpdate' );
|
|
266
|
+
let primaryIssue = '';
|
|
272
267
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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: [
|
|
@@ -468,13 +455,6 @@ export async function infraReportSent( req, res ) {
|
|
|
468
455
|
status: 1,
|
|
469
456
|
ticketDetails: 1,
|
|
470
457
|
issueClosedDate: 1,
|
|
471
|
-
otherscomment: {
|
|
472
|
-
$filter: {
|
|
473
|
-
input: '$ticketActivity',
|
|
474
|
-
as: 'item',
|
|
475
|
-
cond: { $eq: [ '$$item.actionType', 'comment' ] },
|
|
476
|
-
},
|
|
477
|
-
},
|
|
478
458
|
primaryIssue: {
|
|
479
459
|
$filter: {
|
|
480
460
|
input: '$ticketActivity',
|
|
@@ -484,11 +464,6 @@ export async function infraReportSent( req, res ) {
|
|
|
484
464
|
},
|
|
485
465
|
},
|
|
486
466
|
},
|
|
487
|
-
{
|
|
488
|
-
$unwind: {
|
|
489
|
-
path: '$otherscomment', preserveNullAndEmptyArrays: true,
|
|
490
|
-
},
|
|
491
|
-
},
|
|
492
467
|
{
|
|
493
468
|
$unwind: {
|
|
494
469
|
path: '$primaryIssue', preserveNullAndEmptyArrays: true,
|
|
@@ -512,8 +487,6 @@ export async function infraReportSent( req, res ) {
|
|
|
512
487
|
status: 1,
|
|
513
488
|
ticketDetails: 1,
|
|
514
489
|
issueClosedDate: 1,
|
|
515
|
-
ommentText: { $ifNull: [ '$primaryIssue.comment', '-' ] },
|
|
516
|
-
otherscomment: { $ifNull: [ '$otherscomment.comment', '-' ] },
|
|
517
490
|
primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
|
|
518
491
|
secondaryIssue: { $ifNull: [ '$primaryIssue.reasons.secondaryIssue.name', '-' ] },
|
|
519
492
|
},
|
|
@@ -524,12 +497,11 @@ export async function infraReportSent( req, res ) {
|
|
|
524
497
|
ticketDetails: { $first: '$ticketDetails' },
|
|
525
498
|
issueClosedDate: { $first: '$issueClosedDate' },
|
|
526
499
|
basicDetails: { $first: '$basicDetails' },
|
|
527
|
-
commentText: { $last: '$commentText' },
|
|
528
500
|
primaryIssue: { $last: '$primaryIssue' },
|
|
529
501
|
secondaryIssue: { $last: '$secondaryIssue' },
|
|
530
|
-
otherscomment: { $last: '$otherscomment' },
|
|
531
502
|
createdAt: { $first: '$createdAt' },
|
|
532
503
|
status: { $last: '$status' },
|
|
504
|
+
|
|
533
505
|
},
|
|
534
506
|
},
|
|
535
507
|
];
|
|
@@ -542,20 +514,18 @@ export async function infraReportSent( req, res ) {
|
|
|
542
514
|
exportdata.push( {
|
|
543
515
|
'Client ID': element.basicDetails.clientId,
|
|
544
516
|
'Client Name': element.basicDetails.clientName,
|
|
545
|
-
'
|
|
546
|
-
'Store ID': element.basicDetails.
|
|
547
|
-
'Store Name': element.basicDetails.
|
|
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,
|
|
548
520
|
'Issue ': element.primaryIssue,
|
|
549
521
|
'Secondary Issue': element.secondaryIssue,
|
|
522
|
+
'Issue Date & Time': dayjs( element.date ).format( 'YYYY-MM-DD' ),
|
|
550
523
|
'Status ': element.status,
|
|
551
524
|
'Responded By': clientuser && clientuser.userName ? clientuser.userName : '-',
|
|
552
525
|
'Resolved By': tangouser && tangouser.userName ? tangouser.userName : '-',
|
|
553
|
-
'
|
|
554
|
-
'Latest Comment':
|
|
555
|
-
'Activity Log':
|
|
556
|
-
label: 'Link',
|
|
557
|
-
url: `${appConfig.url.domain+'/manage/stores/infra-ticket?storeId='+element.basicDetails.storeId}`,
|
|
558
|
-
},
|
|
526
|
+
'Closed Date & Time': element.issueClosedDate?dayjs( element.issueClosedDate ).format( 'YYYY-MM-DD HH:mm A' ):'-',
|
|
527
|
+
'Latest Comment': '',
|
|
528
|
+
'Activity Log': '',
|
|
559
529
|
} );
|
|
560
530
|
}
|
|
561
531
|
|
|
@@ -567,7 +537,7 @@ export async function infraReportSent( req, res ) {
|
|
|
567
537
|
],
|
|
568
538
|
} );
|
|
569
539
|
let client = await findOneClient( { clientId: req.body.clientId } );
|
|
570
|
-
let avgDownTime = client.ticketConfigs.infraDownTime
|
|
540
|
+
let avgDownTime = client.ticketConfigs.infraDownTime*60;
|
|
571
541
|
let issueList = await findinfraReason( { parentId: { '$exists': false } } );
|
|
572
542
|
const categoryCounts = {};
|
|
573
543
|
let response;
|
|
@@ -591,467 +561,43 @@ export async function infraReportSent( req, res ) {
|
|
|
591
561
|
} ) );
|
|
592
562
|
}
|
|
593
563
|
let reportdate = dayjs().format( 'YYYY-MM-DD' );
|
|
594
|
-
let attachments
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
const html = htmlContent( { ...req.body, Uidomain: Uidomain, issueCount: issueCount, avgDownTime: avgDownTime, reportdate: reportdate, content: response, date: date, domain: appConfig.url.apiDomain } );
|
|
610
|
-
if ( isValidEmail( req.body.email ) ) {
|
|
611
|
-
const result = await sendEmailWithSES( req.body.email, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
|
|
612
|
-
res.sendSuccess( result );
|
|
613
|
-
}
|
|
614
|
-
} catch ( error ) {
|
|
615
|
-
logger.error( { error: error, function: 'infraReportSent' } );
|
|
616
|
-
res.sendError( error, 500 );
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
export async function spocmailchange() {
|
|
620
|
-
let storelist = await findStore( {} );
|
|
621
|
-
for ( let store of storelist ) {
|
|
622
|
-
if ( store && store.spocDetails ) {
|
|
623
|
-
let spoclist = [];
|
|
624
|
-
for ( let spoc of store.spocDetails ) {
|
|
625
|
-
spoc.email = spoc.email.replace( '@', '1@' ),
|
|
626
|
-
spoclist.push( spoc );
|
|
627
|
-
}
|
|
628
|
-
await updateOneStore( { storeId: store.storeId }, { spocDetails: spoclist } );
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
export async function camAngleChangeReport( req, res ) {
|
|
635
|
-
try {
|
|
636
|
-
const currentDate = dayjs();
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
const previousDay = currentDate.subtract( 1, 'day' );
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const formattedPreviousDay = previousDay.format( 'DD-MM-YYYY' );
|
|
643
|
-
const angleChange = await getOpenSearchData( 'camera-angle-change',
|
|
644
|
-
{
|
|
645
|
-
'query': {
|
|
646
|
-
'bool': {
|
|
647
|
-
'must': [
|
|
648
|
-
{
|
|
649
|
-
'term': {
|
|
650
|
-
'date.keyword': formattedPreviousDay,
|
|
651
|
-
},
|
|
652
|
-
},
|
|
653
|
-
{
|
|
654
|
-
'term': {
|
|
655
|
-
'client_id.keyword': req.body.clientId,
|
|
656
|
-
},
|
|
657
|
-
},
|
|
658
|
-
],
|
|
659
|
-
},
|
|
660
|
-
},
|
|
661
|
-
} );
|
|
662
|
-
if ( angleChange.body.hits.hits.length > 0 ) {
|
|
663
|
-
const exportdata = [];
|
|
664
|
-
|
|
665
|
-
for ( let camera of angleChange.body.hits.hits ) {
|
|
666
|
-
let result = camera._source;
|
|
667
|
-
|
|
668
|
-
if ( result && result.cameraAngleChangeStatus && result.camera_info.length > 0 ) {
|
|
669
|
-
for ( let stream of result.camera_info ) {
|
|
670
|
-
let params = {
|
|
671
|
-
Bucket: appConfig.cloud.aws.bucket.cameraAngle,
|
|
672
|
-
file_path: stream.path,
|
|
673
|
-
};
|
|
674
|
-
let Image = await signedUrl( params );
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
let findStore = await findOneStore( { storeId: result.store_id } );
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
exportdata.push( {
|
|
681
|
-
'Store Name': findStore.storeName,
|
|
682
|
-
'Store Code': findStore.storeId,
|
|
683
|
-
'Date Changed': formattedPreviousDay,
|
|
684
|
-
'ImageURL': {
|
|
685
|
-
url: Image,
|
|
686
|
-
label: 'Angle changed Image',
|
|
687
|
-
},
|
|
688
|
-
} );
|
|
689
|
-
}
|
|
564
|
+
let attachments= null;
|
|
565
|
+
if ( exportdata.length>0 ) {
|
|
566
|
+
const wb = new xl.Workbook();
|
|
567
|
+
const ws = wb.addWorksheet( 'Daily report' );
|
|
568
|
+
const headers = Object.keys( exportdata[0] );
|
|
569
|
+
|
|
570
|
+
for ( let i = 0; i < headers.length; i++ ) {
|
|
571
|
+
ws.cell( 1, i + 1 ).string( headers[i] );
|
|
572
|
+
};
|
|
573
|
+
for ( let i = 0; i < exportdata.length; i++ ) {
|
|
574
|
+
const dataRow = exportdata[i];
|
|
575
|
+
for ( let j = 0; j < headers.length; j++ ) {
|
|
576
|
+
const header = headers[j];
|
|
577
|
+
const value = dataRow[header];
|
|
578
|
+
ws.cell( i + 2, j + 1 ).string( value?.toString() );
|
|
690
579
|
}
|
|
691
580
|
}
|
|
692
|
-
let buffer = await
|
|
581
|
+
let buffer = await wb.writeToBuffer();
|
|
693
582
|
|
|
694
|
-
|
|
695
|
-
filename: `
|
|
583
|
+
attachments = {
|
|
584
|
+
filename: `dailyInfraReport- ${reportdate}.xlsx`,
|
|
696
585
|
content: buffer,
|
|
697
586
|
contentType: 'application/xlsx', // e.g., 'application/pdf'
|
|
698
587
|
};
|
|
699
|
-
let subject = `Camera Angle Modified - ${formattedPreviousDay}`;
|
|
700
|
-
let html = `<div>We wanted to inform you that the camera angle in your stores has been adjusted recently.</div>`;
|
|
701
|
-
let result = await sendEmailWithSES( req.body.toMail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
|
|
702
|
-
if ( result ) {
|
|
703
|
-
res.sendSuccess( 'Email send successfully' );
|
|
704
|
-
}
|
|
705
|
-
} else {
|
|
706
|
-
res.sendSuccess( 'No changes in camera Angle' );
|
|
707
588
|
}
|
|
708
|
-
} catch ( error ) {
|
|
709
|
-
logger.error( { error: error, function: 'camAngleChangeList' } );
|
|
710
|
-
res.sendError( error, 500 );
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
589
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
for ( let i = 0; i < headers.length; i++ ) {
|
|
721
|
-
ws.cell( 1, i + 1 ).string( headers[i] );
|
|
722
|
-
};
|
|
723
|
-
for ( let i = 0; i < data.length; i++ ) {
|
|
724
|
-
const dataRow = data[i];
|
|
725
|
-
for ( let j = 0; j < headers.length; j++ ) {
|
|
726
|
-
const header = headers[j];
|
|
727
|
-
const value = dataRow[header];
|
|
728
|
-
if ( value&& 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
|
-
const istTimestamp = dayjs.utc( ticket.createdAt ).tz( 'Asia/Kolkata' ).format( 'HH:mm:ss' );
|
|
888
|
-
|
|
889
|
-
if ( findissue.code == '1003' ) {
|
|
890
|
-
const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
|
|
891
|
-
const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
|
|
892
|
-
const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
|
|
893
|
-
if ( isOccurringTimeEarlier ) {
|
|
894
|
-
findissueEdgeApp = {
|
|
895
|
-
ticketId: ticket.ticketId,
|
|
896
|
-
edgelog: findissue,
|
|
897
|
-
storeId: ticket.basicDetails.storeId,
|
|
898
|
-
primary: 'System Issues',
|
|
899
|
-
secondary: [ 'Malware or Viruses' ],
|
|
900
|
-
};
|
|
901
|
-
updateIssue( findissueEdgeApp );
|
|
902
|
-
finalresult.push( findissueEdgeApp );
|
|
903
|
-
}
|
|
904
|
-
} else if ( findissue.code == '1024' ) {
|
|
905
|
-
const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.data.occuringTime}` );
|
|
906
|
-
const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
|
|
907
|
-
const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
|
|
908
|
-
|
|
909
|
-
const existsInArray = finalresult.some( ( item ) =>
|
|
910
|
-
item.ticketId === ticket.ticketId,
|
|
911
|
-
);
|
|
912
|
-
if ( isOccurringTimeEarlier&&!existsInArray ) {
|
|
913
|
-
findissueEdgeApp = {
|
|
914
|
-
ticketId: ticket.ticketId,
|
|
915
|
-
storeId: ticket.basicDetails.storeId,
|
|
916
|
-
edgelog: findissue.edgelog.data,
|
|
917
|
-
primary: 'Camera Issues',
|
|
918
|
-
secondary: [ 'Camera Not working/RTSP port not working' ],
|
|
919
|
-
};
|
|
920
|
-
updateIssue( findissueEdgeApp );
|
|
921
|
-
finalresult.push( findissueEdgeApp );
|
|
922
|
-
}
|
|
923
|
-
} else if ( findissue.code == '1011' ) {
|
|
924
|
-
const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
|
|
925
|
-
const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
|
|
926
|
-
const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
|
|
927
|
-
|
|
928
|
-
if ( isOccurringTimeEarlier ) {
|
|
929
|
-
findissueEdgeApp = {
|
|
930
|
-
ticketId: ticket.ticketId,
|
|
931
|
-
edgelog: findissue,
|
|
932
|
-
storeId: ticket.basicDetails.storeId,
|
|
933
|
-
primary: 'System Issues',
|
|
934
|
-
secondary: [ 'System is in Sleep Mode' ],
|
|
935
|
-
};
|
|
936
|
-
updateIssue( findissueEdgeApp );
|
|
937
|
-
finalresult.push( findissueEdgeApp );
|
|
938
|
-
}
|
|
939
|
-
} else if ( findissue.code ==='1005' ) {
|
|
940
|
-
const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
|
|
941
|
-
const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
|
|
942
|
-
const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
|
|
943
|
-
if ( isOccurringTimeEarlier ) {
|
|
944
|
-
findissueEdgeApp = {
|
|
945
|
-
ticketId: ticket.ticketId,
|
|
946
|
-
edgelog: findissue,
|
|
947
|
-
storeId: ticket.basicDetails.storeId,
|
|
948
|
-
primary: 'Internet Issues',
|
|
949
|
-
secondary: [ 'Slow Internet Speed' ],
|
|
950
|
-
};
|
|
951
|
-
updateIssue( findissueEdgeApp );
|
|
952
|
-
finalresult.push( findissueEdgeApp );
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
res.sendSuccess( { count: finalresult.length, result: finalresult } );
|
|
959
|
-
} catch ( error ) {
|
|
960
|
-
logger.error( { error: error, function: 'camAngleChangeList' } );
|
|
961
|
-
res.sendError( error, 500 );
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
function bytesToMB( bytes ) {
|
|
965
|
-
return bytes / ( 1024 * 1024 );
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
export async function updateIssue( data ) {
|
|
969
|
-
try {
|
|
970
|
-
let Ticket = await findOneTangoTicket(
|
|
971
|
-
{
|
|
972
|
-
ticketId: data.ticketId,
|
|
973
|
-
},
|
|
974
|
-
);
|
|
590
|
+
const subject = `Daily Digest - Infra Downtime Report - ${reportdate}`;
|
|
591
|
+
const fileContent = readFileSync( join() + '/src/hbs/dailyInfraReport.hbs', 'utf8' );
|
|
592
|
+
const htmlContent = handlebars.compile( fileContent );
|
|
593
|
+
let Uidomain = `${appConfig.url.domain}`;
|
|
975
594
|
|
|
976
|
-
data.issueType = Ticket.issueType;
|
|
977
|
-
data.basicDetails = Ticket.basicDetails;
|
|
978
|
-
data.ticketDetails = Ticket.ticketDetails;
|
|
979
|
-
data.ticketActivity = Ticket.ticketActivity;
|
|
980
|
-
if ( data.primary && data.secondary && data.secondary.length ) {
|
|
981
|
-
let primaryReason = await findOneinfraReason( { name: data.primary } );
|
|
982
|
-
if ( !primaryReason ) {
|
|
983
|
-
return res.sendError( 'Primary Reason Not exists in database', 500 );
|
|
984
|
-
}
|
|
985
|
-
const secondary = [];
|
|
986
|
-
const steptoReslove = [];
|
|
987
|
-
for ( let i = 0; i < data.secondary.length; i++ ) {
|
|
988
|
-
let secondaryReason = await findOneinfraReason( { name: data.secondary[i] } );
|
|
989
|
-
if ( !secondaryReason ) {
|
|
990
|
-
return res.sendError( `secondary Reason - ${data.secondary[i]} Not exists in database`, 500 );
|
|
991
|
-
}
|
|
992
|
-
secondary.push( {
|
|
993
|
-
name: secondaryReason.name,
|
|
994
|
-
} );
|
|
995
|
-
let resolveSteps = [];
|
|
996
|
-
for ( let i = 0; i < secondaryReason.stepstoResolve.length; i++ ) {
|
|
997
|
-
resolveSteps.push( {
|
|
998
|
-
name: secondaryReason.stepstoResolve[i].name,
|
|
999
|
-
} );
|
|
1000
|
-
}
|
|
1001
|
-
steptoReslove.push( {
|
|
1002
|
-
primaryIssue: secondaryReason.name,
|
|
1003
|
-
secondaryIsssue: [ ...resolveSteps ],
|
|
1004
|
-
} );
|
|
1005
|
-
}
|
|
1006
595
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
IdentifiedBy: 'Tango',
|
|
1011
|
-
timeStamp: new Date(),
|
|
1012
|
-
reasons: [ {
|
|
1013
|
-
primaryIssue: primaryReason.name,
|
|
1014
|
-
secondaryIssue: secondary,
|
|
1015
|
-
} ],
|
|
1016
|
-
},
|
|
1017
|
-
);
|
|
1018
|
-
} else {
|
|
1019
|
-
if ( data.primary == 'Application Issues' ) {
|
|
1020
|
-
data.ticketActivity.push( {
|
|
1021
|
-
actionType: 'issueUpdate',
|
|
1022
|
-
actionBy: 'automated',
|
|
1023
|
-
timeStamp: new Date(),
|
|
1024
|
-
IdentifiedBy: 'Tango',
|
|
1025
|
-
reasons: [ {
|
|
1026
|
-
primaryIssue: data.primary,
|
|
1027
|
-
secondaryIssue: [],
|
|
1028
|
-
} ],
|
|
1029
|
-
},
|
|
1030
|
-
);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
if ( data.issueType == 'infra' ) {
|
|
1034
|
-
let client = await findOneClient( { clientId: data.basicDetails.clientId }, { ticketConfigs: 1 } );
|
|
1035
|
-
let statusCheckAlertTime = dayjs().add( client.ticketConfigs.statusCheckAlert, 'hours' ).format( 'YYYY-MM-DD hh:mm' );
|
|
1036
|
-
data.ticketActivity.push( {
|
|
1037
|
-
actionType: 'statusCheck',
|
|
1038
|
-
timeStamp: statusCheckAlertTime,
|
|
1039
|
-
actionBy: 'Tango',
|
|
1040
|
-
IdentifiedBy: 'Tango',
|
|
1041
|
-
timeStamp: new Date(),
|
|
1042
|
-
statusCheckAlertTime: statusCheckAlertTime,
|
|
1043
|
-
} );
|
|
1044
|
-
}
|
|
1045
|
-
let query = {
|
|
1046
|
-
'ticketActivity': data.ticketActivity,
|
|
1047
|
-
'ticketDetails.issueIdentifiedDate': new Date(),
|
|
1048
|
-
'ticketDetails.issueStatus': 'identified',
|
|
1049
|
-
'status': 'inprogress',
|
|
1050
|
-
};
|
|
1051
|
-
await updateOneTangoTicket( { ticketId: data.ticketId }, query );
|
|
596
|
+
const html = htmlContent( { ...req.body, Uidomain: Uidomain, issueCount: issueCount, avgDownTime: avgDownTime, reportdate: reportdate, content: response, date: date, domain: appConfig.url.apiDomain } );
|
|
597
|
+
const result = await sendEmailWithSES( req.body.email, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
|
|
598
|
+
res.sendSuccess( result );
|
|
1052
599
|
} catch ( error ) {
|
|
1053
|
-
logger.error( { error: error, function: '
|
|
600
|
+
logger.error( { error: error, function: 'infraReportSent' } );
|
|
1054
601
|
res.sendError( error, 500 );
|
|
1055
602
|
}
|
|
1056
603
|
}
|
|
1057
|
-
|