tango-app-api-infra 3.0.38-dev → 3.0.40-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 +4 -3
- package/src/controllers/infra.controllers.js +104 -6
- package/src/controllers/internalInfra.controller.js +469 -5
- package/src/hbs/closeTicekt.hbs +289 -0
- package/src/hbs/createTicket.hbs +288 -0
- package/src/hbs/dailyInfraReport.hbs +315 -0
- package/src/hbs/refreshTicket.hbs +292 -0
- package/src/routes/internalInfra.routes.js +3 -1
- package/src/validations/infra.validation.js +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-infra",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.40-dev",
|
|
4
4
|
"description": "infra",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,13 +17,14 @@
|
|
|
17
17
|
"cors": "^2.8.5",
|
|
18
18
|
"dayjs": "^1.11.10",
|
|
19
19
|
"dotenv": "^16.4.5",
|
|
20
|
+
"excel4node": "^1.8.2",
|
|
20
21
|
"express": "^4.18.3",
|
|
21
22
|
"express-fileupload": "^1.5.0",
|
|
22
23
|
"handlebars": "^4.7.8",
|
|
23
24
|
"mongodb": "^6.4.0",
|
|
24
25
|
"nodemon": "^3.1.0",
|
|
25
|
-
"tango-api-schema": "^2.0.
|
|
26
|
-
"tango-app-api-middleware": "^1.0.
|
|
26
|
+
"tango-api-schema": "^2.0.77",
|
|
27
|
+
"tango-app-api-middleware": "^1.0.54-dev",
|
|
27
28
|
"winston": "^3.12.0",
|
|
28
29
|
"winston-daily-rotate-file": "^5.0.0"
|
|
29
30
|
},
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import { createTangoTicket, findOneTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
|
|
4
4
|
import { createinfraReason, findinfraReason } from '../services/infraReason.service.js';
|
|
5
|
-
import { updateOneStore } from '../services/store.service.js';
|
|
6
|
-
import { logger, fileUpload, signedUrl } from 'tango-app-api-middleware';
|
|
5
|
+
import { updateOneStore, findStore } from '../services/store.service.js';
|
|
6
|
+
import { logger, fileUpload, signedUrl, sendEmailWithSES, getOpenSearchData, appConfig } 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';
|
|
10
|
+
import { readFileSync } from 'fs';
|
|
11
|
+
import { join } from 'path';
|
|
12
|
+
import handlebars from 'handlebars';
|
|
13
|
+
import { findOneGroup } from '../services/group.service.js';
|
|
10
14
|
export async function createTicket( req, res ) {
|
|
11
15
|
try {
|
|
12
16
|
req.body.issueDate = new Date( req.body.Date );
|
|
@@ -22,7 +26,55 @@ export async function createTicket( req, res ) {
|
|
|
22
26
|
if ( req.body.issueType == 'installation' ) {
|
|
23
27
|
req.body.ticketId = 'TE_INS_' + new Date().valueOf();
|
|
24
28
|
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
let downTimeQuery = {
|
|
32
|
+
'size': 1,
|
|
33
|
+
'query': {
|
|
34
|
+
'bool': {
|
|
35
|
+
'must': [
|
|
36
|
+
{
|
|
37
|
+
'term': {
|
|
38
|
+
'doc.date.keyword': dayjs( req.body.issueDate ).format( 'DD-MM-YYYY' ),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
'term': {
|
|
43
|
+
'doc.store_id.keyword': req.body.basicDetails.storeId,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
],
|
|
48
|
+
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
let downtimetotal;
|
|
53
|
+
const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
|
|
54
|
+
let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
|
|
55
|
+
if ( streamwiseDowntime.length > 0 ) {
|
|
56
|
+
const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
|
|
57
|
+
return accumulator + currentValue.down_time;
|
|
58
|
+
}, 0 );
|
|
59
|
+
const average = sum / streamwiseDowntime.length;
|
|
60
|
+
downtimetotal = Math.round( average );
|
|
61
|
+
} else {
|
|
62
|
+
downtimetotal = 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
25
66
|
let create = await createTangoTicket( req.body );
|
|
67
|
+
let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
|
|
68
|
+
const attachments = null;
|
|
69
|
+
const subject = `Tango Eye - Ticket Created for ${req.body.basicDetails.storeName}`;
|
|
70
|
+
const fileContent = readFileSync( join() + '/src/hbs/createTicket.hbs', 'utf8' );
|
|
71
|
+
const htmlContent = handlebars.compile( fileContent );
|
|
72
|
+
let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${req.body.basicDetails.storeId}`;
|
|
73
|
+
|
|
74
|
+
const html = htmlContent( { ...req.body, Uidomain: Uidomain, domain: appConfig.url.apiDomain, date: dayjs( req.body.issueDate ).format( 'YYYY-MM-DD' ), downtimetotal: downtimetotal, Timestamp: Timestamp } );
|
|
75
|
+
await sendEmailWithSES( req.body.spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
|
|
76
|
+
|
|
77
|
+
|
|
26
78
|
if ( create ) {
|
|
27
79
|
res.sendSuccess( 'Ticket Created Successfully' );
|
|
28
80
|
}
|
|
@@ -148,7 +200,29 @@ export async function secondaryReason( req, res ) {
|
|
|
148
200
|
|
|
149
201
|
export async function updateTicketIssue( req, res ) {
|
|
150
202
|
try {
|
|
151
|
-
let
|
|
203
|
+
let query = {};
|
|
204
|
+
if ( req.user.userType == 'client' ) {
|
|
205
|
+
query = {
|
|
206
|
+
'ticketActivity': req.body.ticketActivity,
|
|
207
|
+
'cameraList': req.body.cameraList,
|
|
208
|
+
'ticketDetails.issueIdentifiedDate': new Date(),
|
|
209
|
+
'ticketDetails.issueIdentifiedBy': req.body.issueIdentifiedBy,
|
|
210
|
+
'ticketDetails.addressingClient': req.user._id,
|
|
211
|
+
'ticketDetails.issueStatus': 'identified',
|
|
212
|
+
'status': 'inprogress',
|
|
213
|
+
};
|
|
214
|
+
} else {
|
|
215
|
+
query = {
|
|
216
|
+
'ticketActivity': req.body.ticketActivity,
|
|
217
|
+
'cameraList': req.body.cameraList,
|
|
218
|
+
'ticketDetails.issueIdentifiedDate': new Date(),
|
|
219
|
+
'ticketDetails.issueIdentifiedBy': req.body.issueIdentifiedBy,
|
|
220
|
+
'ticketDetails.addressingUser': req.user._id,
|
|
221
|
+
'ticketDetails.issueStatus': 'identified',
|
|
222
|
+
'status': 'inprogress',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, query );
|
|
152
226
|
if ( req.body.ticketDetails.ticketType === 'refreshticket' ) {
|
|
153
227
|
await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketDetails.refreshTicketStatus': 'identified' } );
|
|
154
228
|
}
|
|
@@ -332,12 +406,15 @@ export async function emailUserList( req, res ) {
|
|
|
332
406
|
{
|
|
333
407
|
$group: {
|
|
334
408
|
_id: null,
|
|
409
|
+
assignedValue: { $push: '$assignedValue' },
|
|
410
|
+
assignedType: { $first: '$assignedType' },
|
|
335
411
|
storeList: { $push: '$assignedValue' },
|
|
336
412
|
},
|
|
337
413
|
},
|
|
338
414
|
{
|
|
339
415
|
$project: {
|
|
340
|
-
|
|
416
|
+
assignedType: 1,
|
|
417
|
+
assignedValue: 1,
|
|
341
418
|
assignedStore: { $size: '$storeList' },
|
|
342
419
|
},
|
|
343
420
|
},
|
|
@@ -353,6 +430,8 @@ export async function emailUserList( req, res ) {
|
|
|
353
430
|
email: 1,
|
|
354
431
|
role: 1,
|
|
355
432
|
emailAlert: 1,
|
|
433
|
+
assignedValue: '$assigned.assignedValue',
|
|
434
|
+
assignedType: { $ifNull: [ '$assigned.assignedType', 0 ] },
|
|
356
435
|
infraAlert: { $ifNull: [ '$emailAlert.infra', false ] },
|
|
357
436
|
assigned: { $ifNull: [ '$assigned.assignedStore', 0 ] },
|
|
358
437
|
isActive: 1,
|
|
@@ -384,6 +463,25 @@ export async function emailUserList( req, res ) {
|
|
|
384
463
|
);
|
|
385
464
|
}
|
|
386
465
|
const result = await aggregateUser( query );
|
|
466
|
+
for ( let user of result ) {
|
|
467
|
+
if ( user.role == 'superadmin' ) {
|
|
468
|
+
let storelist = await findStore( { clientId: user.clientId, status: 'active' }, { storeName: 1 } );
|
|
469
|
+
user.assigned = storelist.length;
|
|
470
|
+
user.assignedValue = storelist;
|
|
471
|
+
} else if ( user.role != 'superadmin' ) {
|
|
472
|
+
if ( user.assignedType == 'group' ) {
|
|
473
|
+
for ( let group of user.assignedValue ) {
|
|
474
|
+
let groupdata = await findOneGroup( { groupName: group } );
|
|
475
|
+
let storelist = await findStore( { storeId: { $in: groupdata.storeList } }, { storeName: 1 } );
|
|
476
|
+
user.assigned = storelist.length;
|
|
477
|
+
user.assignedValue = storelist;
|
|
478
|
+
}
|
|
479
|
+
} else if ( user.assignedType == 'store' ) {
|
|
480
|
+
let storelist = await findStore( { storeId: { $in: user.assignedValue } }, { storeName: 1 } );
|
|
481
|
+
user.assignedValue = storelist;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
387
485
|
res.sendSuccess( { count: count.length, result: result } );
|
|
388
486
|
} catch ( error ) {
|
|
389
487
|
logger.error( { error: error, function: 'emailUserList' } );
|
|
@@ -394,13 +492,13 @@ export async function saveInfraEmailConfig( req, res ) {
|
|
|
394
492
|
try {
|
|
395
493
|
let inputData = req.body;
|
|
396
494
|
|
|
397
|
-
|
|
495
|
+
await updateoneClient( { clientId: inputData.clientId }, {
|
|
398
496
|
'ticketConfigs.infraReport': {
|
|
399
497
|
start: inputData.start,
|
|
400
498
|
end: inputData.end,
|
|
401
499
|
},
|
|
402
500
|
} );
|
|
403
|
-
|
|
501
|
+
|
|
404
502
|
if ( inputData.userList && inputData.userList.length > 0 ) {
|
|
405
503
|
for ( let user of inputData.userList ) {
|
|
406
504
|
await updateOneUser( { email: user.email }, {
|