tango-app-api-infra 3.0.42-dev → 3.0.44-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
|
@@ -10,7 +10,7 @@ import handlebars from 'handlebars';
|
|
|
10
10
|
dayjs.extend( utc );
|
|
11
11
|
dayjs.extend( timezone );
|
|
12
12
|
import { sendEmailWithSES } from 'tango-app-api-middleware';
|
|
13
|
-
import { createClient, findClient, aggregateClient } from '../services/client.service.js';
|
|
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';
|
|
16
16
|
import { findOneGroup } from '../services/group.service.js';
|
|
@@ -435,17 +435,15 @@ export async function infraReportSent( req, res ) {
|
|
|
435
435
|
let date;
|
|
436
436
|
if ( req.body.type == 'start' ) {
|
|
437
437
|
date = dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
|
|
438
|
-
} else if ( req.body.
|
|
438
|
+
} else if ( req.body.type == 'end' ) {
|
|
439
439
|
date = dayjs().format( 'YYYY-MM-DD' );
|
|
440
440
|
};
|
|
441
|
-
|
|
442
441
|
let query = [ {
|
|
443
442
|
$match: {
|
|
444
443
|
$and: [
|
|
445
444
|
{ issueDate: new Date( date ) },
|
|
446
445
|
{ 'basicDetails.storeId': { $in: req.body.storeList } },
|
|
447
446
|
{ issueType: 'infra' },
|
|
448
|
-
{ 'ticketDetails.issueStatus': 'identified' },
|
|
449
447
|
],
|
|
450
448
|
},
|
|
451
449
|
},
|
|
@@ -530,57 +528,16 @@ export async function infraReportSent( req, res ) {
|
|
|
530
528
|
'Activity Log': '',
|
|
531
529
|
} );
|
|
532
530
|
}
|
|
533
|
-
let issueCount = await countDocumentsTangoTicket( {
|
|
534
531
|
|
|
532
|
+
let issueCount = await countDocumentsTangoTicket( {
|
|
535
533
|
$and: [
|
|
536
534
|
{ issueDate: new Date( date ) },
|
|
537
535
|
{ 'basicDetails.storeId': { $in: req.body.storeList } },
|
|
538
536
|
{ issueType: 'infra' },
|
|
539
|
-
{ 'ticketDetails.issueStatus': 'identified' },
|
|
540
537
|
],
|
|
541
|
-
|
|
542
538
|
} );
|
|
543
|
-
let
|
|
544
|
-
|
|
545
|
-
let downTimeQuery = {
|
|
546
|
-
'size': 1,
|
|
547
|
-
'query': {
|
|
548
|
-
'bool': {
|
|
549
|
-
'must': [
|
|
550
|
-
{
|
|
551
|
-
'term': {
|
|
552
|
-
'doc.date.keyword': dayjs( date ).format( 'DD-MM-YYYY' ),
|
|
553
|
-
},
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
'term': {
|
|
557
|
-
'doc.store_id.keyword': storedata,
|
|
558
|
-
},
|
|
559
|
-
},
|
|
560
|
-
|
|
561
|
-
],
|
|
562
|
-
|
|
563
|
-
},
|
|
564
|
-
},
|
|
565
|
-
};
|
|
566
|
-
let downtimetotal;
|
|
567
|
-
const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
|
|
568
|
-
let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
|
|
569
|
-
if ( streamwiseDowntime.length > 0 ) {
|
|
570
|
-
const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
|
|
571
|
-
return accumulator + currentValue.down_time;
|
|
572
|
-
}, 0 );
|
|
573
|
-
const average = sum / streamwiseDowntime.length;
|
|
574
|
-
downtimetotal = Math.round( average );
|
|
575
|
-
} else {
|
|
576
|
-
downtimetotal = 0;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
finalcount = finalcount + downtimetotal;
|
|
580
|
-
}
|
|
581
|
-
let avgDownTime = Math.round( finalcount / req.body.storeList.length );
|
|
582
|
-
|
|
583
|
-
|
|
539
|
+
let client = await findOneClient( { clientId: req.body.clientId } );
|
|
540
|
+
let avgDownTime = client.ticketConfigs.infraDownTime*60;
|
|
584
541
|
let issueList = await findinfraReason( { parentId: { '$exists': false } } );
|
|
585
542
|
const categoryCounts = {};
|
|
586
543
|
let response;
|
|
@@ -604,28 +561,32 @@ export async function infraReportSent( req, res ) {
|
|
|
604
561
|
} ) );
|
|
605
562
|
}
|
|
606
563
|
let reportdate = dayjs().format( 'YYYY-MM-DD' );
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
for ( let
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
|
|
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() );
|
|
579
|
+
}
|
|
620
580
|
}
|
|
581
|
+
let buffer = await wb.writeToBuffer();
|
|
582
|
+
|
|
583
|
+
attachments = {
|
|
584
|
+
filename: `dailyInfraReport- ${reportdate}.xlsx`,
|
|
585
|
+
content: buffer,
|
|
586
|
+
contentType: 'application/xlsx', // e.g., 'application/pdf'
|
|
587
|
+
};
|
|
621
588
|
}
|
|
622
|
-
let buffer = await wb.writeToBuffer();
|
|
623
589
|
|
|
624
|
-
const attachments = {
|
|
625
|
-
filename: `dailyInfraReport- ${reportdate}.xlsx`,
|
|
626
|
-
content: buffer,
|
|
627
|
-
contentType: 'application/xlsx', // e.g., 'application/pdf'
|
|
628
|
-
};
|
|
629
590
|
const subject = `Daily Digest - Infra Downtime Report - ${reportdate}`;
|
|
630
591
|
const fileContent = readFileSync( join() + '/src/hbs/dailyInfraReport.hbs', 'utf8' );
|
|
631
592
|
const htmlContent = handlebars.compile( fileContent );
|