tango-app-api-report 3.3.0 → 3.3.2
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-report",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "report",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"nodemon": "^3.1.0",
|
|
27
27
|
"swagger-ui-express": "^5.0.0",
|
|
28
28
|
"tango-api-schema": "^2.1.32",
|
|
29
|
-
"tango-app-api-middleware": "^3.1.
|
|
29
|
+
"tango-app-api-middleware": "^3.1.43",
|
|
30
30
|
"winston": "^3.12.0",
|
|
31
31
|
"winston-daily-rotate-file": "^5.0.0"
|
|
32
32
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deleteOneReport, findOneReport, findReport, reportCreate, reportGet, reportGetSingle, reportUpdate } from '../service/report.service.js';
|
|
2
|
-
import { fileUpload, getObject, getOpenSearchData, insertOpenSearchData, listFileByPath, logger, sendMessageToQueue } from 'tango-app-api-middleware';
|
|
2
|
+
import { convertTimestampToDateTime, fileUpload, getObject, getOpenSearchData, insertOpenSearchData, listFileByPath, logger, sendMessageToQueue } from 'tango-app-api-middleware';
|
|
3
3
|
import { findOneUser, getUserNameEmailById } from '../service/user.service.js';
|
|
4
4
|
import { updateOneBasePriceModel } from '../service/basePrice.service.js';
|
|
5
5
|
import { aggregateClient } from '../service/client.service.js';
|
|
@@ -257,19 +257,20 @@ export async function generateReport( req, res ) {
|
|
|
257
257
|
if ( sqsQueue.MessageId ) {
|
|
258
258
|
const log = {
|
|
259
259
|
userName: req.user.userName,
|
|
260
|
-
Date: new Date(),
|
|
261
260
|
userId: req.user._id,
|
|
262
261
|
logType: 'report',
|
|
263
262
|
logSubType: 'generateReport',
|
|
264
263
|
logData: {
|
|
265
|
-
clientName: req.report?.clientName,
|
|
264
|
+
// clientName: req.report?.clientName,
|
|
266
265
|
fileDate: inputData.fileDate,
|
|
267
266
|
reportName: req.report?.reportConfigs?.reportName,
|
|
268
|
-
clientId: inputData.
|
|
267
|
+
clientId: inputData.clientId,
|
|
269
268
|
sqsMessageId: sqsQueue.MessageId,
|
|
270
269
|
},
|
|
270
|
+
createdAt: Date.now(),
|
|
271
271
|
};
|
|
272
|
-
|
|
272
|
+
logger.info( { auditLog: openSearch.auditLog, openSearch: openSearch } );
|
|
273
|
+
await insertOpenSearchData( openSearch.auditLog, log );
|
|
273
274
|
|
|
274
275
|
return res.sendSuccess( { result: 'Report has been Initiated Sucessfully' } );
|
|
275
276
|
}
|
|
@@ -283,6 +284,7 @@ export async function generateReport( req, res ) {
|
|
|
283
284
|
export async function uploadManualReport( req, res ) {
|
|
284
285
|
try {
|
|
285
286
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
287
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
286
288
|
const inputData = req.body;
|
|
287
289
|
const name = inputData.fileName;
|
|
288
290
|
const regex = /^(\d{2}-\d{2}-\d{4})_(.*?)\.([a-zA-Z0-9]+)$/;
|
|
@@ -321,7 +323,6 @@ export async function uploadManualReport( req, res ) {
|
|
|
321
323
|
}
|
|
322
324
|
const log = {
|
|
323
325
|
userName: user.userName,
|
|
324
|
-
Date: new Date(),
|
|
325
326
|
userId: req.user._id,
|
|
326
327
|
logType: 'report',
|
|
327
328
|
logSubType: 'uploadReport',
|
|
@@ -330,9 +331,10 @@ export async function uploadManualReport( req, res ) {
|
|
|
330
331
|
reportName: req.report?.reportConfigs?.reportName,
|
|
331
332
|
clientId: data.clientId,
|
|
332
333
|
},
|
|
334
|
+
createdAt: Date.now(),
|
|
333
335
|
};
|
|
334
336
|
logger.info( { log: log } );
|
|
335
|
-
|
|
337
|
+
await insertOpenSearchData( openSearch.auditLog, log );
|
|
336
338
|
return res.sendSuccess( { result: 'uploaded Sucessfully' } );
|
|
337
339
|
} else {
|
|
338
340
|
return res.sendError( 'File Name is Incorrect', 400 );
|
|
@@ -398,6 +400,7 @@ export async function dowloadReport( req, res ) {
|
|
|
398
400
|
export async function sendReport( req, res ) {
|
|
399
401
|
try {
|
|
400
402
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
403
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
401
404
|
const sqs = JSON.parse( process.env.SQS );
|
|
402
405
|
const sesConfig = JSON.parse( process.env.SES );
|
|
403
406
|
const inputData = req.body;
|
|
@@ -463,6 +466,7 @@ export async function sendReport( req, res ) {
|
|
|
463
466
|
QueueUrl: `${sqs.url}${sqs.sendReport}`,
|
|
464
467
|
MessageBody: JSON.stringify( {
|
|
465
468
|
file_date: inputData.fileDate,
|
|
469
|
+
reportName: req.report?.reportConfigs?.reportName,
|
|
466
470
|
client_name: req.report?.reportConfigs?.reportName,
|
|
467
471
|
client_id: Number( inputData.clientId ),
|
|
468
472
|
file_name: regionalKey,
|
|
@@ -474,7 +478,6 @@ export async function sendReport( req, res ) {
|
|
|
474
478
|
logger.info( 'successfully Pushed to SQS ' + `${JSON.stringify( sqsQueue )}`, 'Send Report' );
|
|
475
479
|
const log = {
|
|
476
480
|
userName: user.userName,
|
|
477
|
-
Date: new Date(),
|
|
478
481
|
userId: user._id,
|
|
479
482
|
logType: 'report',
|
|
480
483
|
logSubType: 'sendReport',
|
|
@@ -482,10 +485,12 @@ export async function sendReport( req, res ) {
|
|
|
482
485
|
fileDate: inputData.fileDate,
|
|
483
486
|
reportName: req.report?.reportConfigs?.reportName,
|
|
484
487
|
clientId: getReportList[0].clientId,
|
|
488
|
+
sqsMessageId: sqsQueue.MessageId,
|
|
485
489
|
},
|
|
490
|
+
createdAt: Date.now(),
|
|
486
491
|
};
|
|
487
492
|
logger.info( { log: log } );
|
|
488
|
-
|
|
493
|
+
await insertOpenSearchData( openSearch.auditLog, log );
|
|
489
494
|
return res.sendSuccess( { result: 'Report has been Sent Successfully' } );
|
|
490
495
|
} else {
|
|
491
496
|
return res.sendError( ' Message does not Sent & Report has been Sent Successfully', 500 );
|
|
@@ -500,7 +505,9 @@ export async function sendReport( req, res ) {
|
|
|
500
505
|
export async function getReportLog( req, res ) {
|
|
501
506
|
try {
|
|
502
507
|
const inputData = req.body;
|
|
503
|
-
const
|
|
508
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
509
|
+
const logData =[];
|
|
510
|
+
const reportLog = await getOpenSearchData( openSearch.auditLog,
|
|
504
511
|
{
|
|
505
512
|
'size': 100,
|
|
506
513
|
'query': {
|
|
@@ -516,6 +523,11 @@ export async function getReportLog( req, res ) {
|
|
|
516
523
|
'logData.fileDate.keyword': inputData.fileDate,
|
|
517
524
|
},
|
|
518
525
|
},
|
|
526
|
+
{
|
|
527
|
+
'term': {
|
|
528
|
+
'logData.clientId.keyword': inputData.clientId,
|
|
529
|
+
},
|
|
530
|
+
},
|
|
519
531
|
|
|
520
532
|
],
|
|
521
533
|
|
|
@@ -523,10 +535,24 @@ export async function getReportLog( req, res ) {
|
|
|
523
535
|
},
|
|
524
536
|
|
|
525
537
|
} );
|
|
526
|
-
|
|
538
|
+
logger.info( { reportLog: reportLog } );
|
|
539
|
+
if ( reportLog.body.hits.hits.length > 0 ) {
|
|
540
|
+
const sourcesArray = reportLog.body.hits.hits.map( ( hit ) => hit._source );
|
|
541
|
+
for ( const i of sourcesArray ) { // Loop through sourcesArray, not result._doc.camera
|
|
542
|
+
const convertedTime = await convertTimestampToDateTime( i.createdAt );
|
|
543
|
+
logData.push( {
|
|
544
|
+
...i, // Spread the individual log object
|
|
545
|
+
time: convertedTime, // Add the converted time
|
|
546
|
+
} );
|
|
547
|
+
}
|
|
548
|
+
return res.sendSuccess( { result: logData } );
|
|
549
|
+
} else {
|
|
550
|
+
return res.sendError( 'No data found', 204 );
|
|
551
|
+
}
|
|
527
552
|
} catch ( error ) {
|
|
553
|
+
const err = error.message || 'Internal Server Error';
|
|
528
554
|
logger.info( { error: error } );
|
|
529
|
-
return res.sendError(
|
|
555
|
+
return res.sendError( err, 500 );
|
|
530
556
|
}
|
|
531
557
|
}
|
|
532
558
|
export async function updateBasePrice( req, res ) {
|
|
@@ -49,13 +49,13 @@ reportRouter.get( '/get-report-list', isAllowedSessionHandler,
|
|
|
49
49
|
authorize( { userType: [ 'tango' ], access: [
|
|
50
50
|
{ featureName: 'manage', name: 'reports', permissions: [ 'isView' ] },
|
|
51
51
|
] } ),
|
|
52
|
-
validate( getReportListValid ),
|
|
52
|
+
validate( getReportListValid ), isFolderExist, getReportList );
|
|
53
53
|
|
|
54
54
|
reportRouter.get( '/download-report', isAllowedSessionHandler,
|
|
55
55
|
authorize( { userType: [ 'tango' ], access: [
|
|
56
56
|
{ featureName: 'manage', name: 'reports', permissions: [ 'isEdit' ] },
|
|
57
57
|
] } ),
|
|
58
|
-
validate( downloadReportValid ),
|
|
58
|
+
validate( downloadReportValid ), isFileExist, dowloadReport );
|
|
59
59
|
|
|
60
60
|
reportRouter.post( '/send-report', isAllowedSessionHandler,
|
|
61
61
|
authorize( { userType: [ 'tango' ], access: [
|
|
@@ -7,7 +7,7 @@ export async function isReportEnable( req, res, next ) {
|
|
|
7
7
|
const inputData = req.method !== 'GET'? req.body: req.query;
|
|
8
8
|
const getReportName = await findOneClient( { 'clientId': inputData.clientId, 'status': { $in: [ 'active', 'hold' ] }, 'reportConfigs.report': true }, { '_id': 0, 'reportConfigs.reportName': 1, 'clientName': 1 } );
|
|
9
9
|
if ( !getReportName ) {
|
|
10
|
-
return res.sendError( 'This action was
|
|
10
|
+
return res.sendError( 'This action was forbidden1', 403 );
|
|
11
11
|
}
|
|
12
12
|
req.report = getReportName;
|
|
13
13
|
return next();
|
|
@@ -27,7 +27,7 @@ export async function isSendReportEnable( req, res, next ) {
|
|
|
27
27
|
req.report = getReportName;
|
|
28
28
|
return next();
|
|
29
29
|
} catch ( error ) {
|
|
30
|
-
logger.error( { error: error, message: req.body, function: '
|
|
30
|
+
logger.error( { error: error, message: req.body, function: 'isSendReportEnable' } );
|
|
31
31
|
return res.sendError( error, 500 );
|
|
32
32
|
}
|
|
33
33
|
}
|