tango-app-api-report 3.1.2 → 3.3.0
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
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "report",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"nodemailer": "^6.9.13",
|
|
26
26
|
"nodemon": "^3.1.0",
|
|
27
27
|
"swagger-ui-express": "^5.0.0",
|
|
28
|
-
"tango-api-schema": "^2.
|
|
29
|
-
"tango-app-api-middleware": "^3.1.
|
|
28
|
+
"tango-api-schema": "^2.1.32",
|
|
29
|
+
"tango-app-api-middleware": "^3.1.42",
|
|
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 {
|
|
2
|
+
import { 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';
|
|
@@ -15,6 +15,7 @@ dayjs.extend( timezone );
|
|
|
15
15
|
|
|
16
16
|
export async function createReport( req, res ) {
|
|
17
17
|
try {
|
|
18
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
18
19
|
const createReport = await reportCreate( {
|
|
19
20
|
clientId: req.params?.id, fileName: req.body?.fileName, fileType: req.body?.fileType, email: req.body?.email,
|
|
20
21
|
} );
|
|
@@ -33,7 +34,7 @@ export async function createReport( req, res ) {
|
|
|
33
34
|
showTo: [ 'tango' ],
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
await insertOpenSearchData(
|
|
37
|
+
await insertOpenSearchData( openSearch.activityLog, logObj );
|
|
37
38
|
if ( createReport ) {
|
|
38
39
|
res.sendSuccess( { result: 'Created Successfully' } );
|
|
39
40
|
}
|
|
@@ -73,6 +74,7 @@ export async function getSingleReport( req, res ) {
|
|
|
73
74
|
|
|
74
75
|
export async function updateReport( req, res ) {
|
|
75
76
|
try {
|
|
77
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
76
78
|
const previousReport = await reportGetSingle( {
|
|
77
79
|
_id: req.params?.id,
|
|
78
80
|
} );
|
|
@@ -97,7 +99,7 @@ export async function updateReport( req, res ) {
|
|
|
97
99
|
|
|
98
100
|
};
|
|
99
101
|
|
|
100
|
-
await insertOpenSearchData(
|
|
102
|
+
await insertOpenSearchData( openSearch.activityLog, logObj );
|
|
101
103
|
if ( updateAck ) {
|
|
102
104
|
res.sendSuccess( { result: 'Updated Successfully' } );
|
|
103
105
|
}
|
|
@@ -128,7 +130,6 @@ export async function clientReportList( req, res ) {
|
|
|
128
130
|
$match: {
|
|
129
131
|
$and: [
|
|
130
132
|
{ 'reportConfigs.report': { $eq: true } },
|
|
131
|
-
{ status: { $eq: 'active' } },
|
|
132
133
|
{ clientId: { $in: inputData.clientId } },
|
|
133
134
|
],
|
|
134
135
|
|
|
@@ -139,6 +140,7 @@ export async function clientReportList( req, res ) {
|
|
|
139
140
|
clientId: 1,
|
|
140
141
|
tangoId: 1,
|
|
141
142
|
clientName: 1,
|
|
143
|
+
status: 1,
|
|
142
144
|
daysDifference: 1,
|
|
143
145
|
datesArray: {
|
|
144
146
|
$map: {
|
|
@@ -164,6 +166,21 @@ export async function clientReportList( req, res ) {
|
|
|
164
166
|
clientName: 1,
|
|
165
167
|
tangoId: 1,
|
|
166
168
|
fileDate: '$datesArray',
|
|
169
|
+
status: 1,
|
|
170
|
+
isSendEnable: {
|
|
171
|
+
$cond: [
|
|
172
|
+
{ $eq: [ '$status', 'active' ] },
|
|
173
|
+
true,
|
|
174
|
+
false,
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
isGenerateEnable: {
|
|
178
|
+
$cond: [
|
|
179
|
+
{ $in: [ '$status', [ 'active', 'hold' ] ] },
|
|
180
|
+
true,
|
|
181
|
+
false,
|
|
182
|
+
],
|
|
183
|
+
},
|
|
167
184
|
},
|
|
168
185
|
},
|
|
169
186
|
];
|
|
@@ -194,6 +211,10 @@ export async function clientReportList( req, res ) {
|
|
|
194
211
|
clientId: { $regex: inputData.searchValue, $options: 'i' },
|
|
195
212
|
|
|
196
213
|
},
|
|
214
|
+
{
|
|
215
|
+
status: { $regex: inputData.searchValue, $options: 'i' },
|
|
216
|
+
|
|
217
|
+
},
|
|
197
218
|
],
|
|
198
219
|
},
|
|
199
220
|
},
|
|
@@ -220,9 +241,11 @@ export async function clientReportList( req, res ) {
|
|
|
220
241
|
|
|
221
242
|
export async function generateReport( req, res ) {
|
|
222
243
|
try {
|
|
244
|
+
const sqs = JSON.parse( process.env.SQS );
|
|
245
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
223
246
|
const inputData = req.body;
|
|
224
247
|
const sqsProduceQueue = {
|
|
225
|
-
QueueUrl: `${
|
|
248
|
+
QueueUrl: `${sqs.url}${sqs.generateReport}`,
|
|
226
249
|
MessageBody: JSON.stringify( {
|
|
227
250
|
file_date: inputData.fileDate,
|
|
228
251
|
client_name: req.report?.reportConfigs?.reportName,
|
|
@@ -246,7 +269,7 @@ export async function generateReport( req, res ) {
|
|
|
246
269
|
sqsMessageId: sqsQueue.MessageId,
|
|
247
270
|
},
|
|
248
271
|
};
|
|
249
|
-
await insertOpenSearchData(
|
|
272
|
+
await insertOpenSearchData( openSearch.activityLog, log );
|
|
250
273
|
|
|
251
274
|
return res.sendSuccess( { result: 'Report has been Initiated Sucessfully' } );
|
|
252
275
|
}
|
|
@@ -259,6 +282,7 @@ export async function generateReport( req, res ) {
|
|
|
259
282
|
|
|
260
283
|
export async function uploadManualReport( req, res ) {
|
|
261
284
|
try {
|
|
285
|
+
const bucket = JSON.parse( process.env.BUCKET );
|
|
262
286
|
const inputData = req.body;
|
|
263
287
|
const name = inputData.fileName;
|
|
264
288
|
const regex = /^(\d{2}-\d{2}-\d{4})_(.*?)\.([a-zA-Z0-9]+)$/;
|
|
@@ -281,7 +305,7 @@ export async function uploadManualReport( req, res ) {
|
|
|
281
305
|
}
|
|
282
306
|
logger.info( { files: req.files } );
|
|
283
307
|
const uploadDataParams = {
|
|
284
|
-
Bucket:
|
|
308
|
+
Bucket: bucket.reportBucket,
|
|
285
309
|
Key: `${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
|
|
286
310
|
fileName: inputData.fileName,
|
|
287
311
|
body: req.files.files.data,
|
|
@@ -321,9 +345,10 @@ export async function uploadManualReport( req, res ) {
|
|
|
321
345
|
|
|
322
346
|
export async function getReportList( req, res ) {
|
|
323
347
|
try {
|
|
348
|
+
const bucket = JSON.parse( process.env.BUCKET );
|
|
324
349
|
const inputData = req.query;
|
|
325
350
|
const fetchData = {
|
|
326
|
-
Bucket:
|
|
351
|
+
Bucket: bucket.reportBucket,
|
|
327
352
|
file_path: `${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
|
|
328
353
|
};
|
|
329
354
|
const folderPath = await listFileByPath( fetchData );
|
|
@@ -345,9 +370,10 @@ export async function getReportList( req, res ) {
|
|
|
345
370
|
|
|
346
371
|
export async function dowloadReport( req, res ) {
|
|
347
372
|
try {
|
|
373
|
+
const bucket = JSON.parse( process.env.BUCKET );
|
|
348
374
|
const inputData = req.query;
|
|
349
375
|
const params = {
|
|
350
|
-
Bucket:
|
|
376
|
+
Bucket: bucket.reportBucket,
|
|
351
377
|
Key: inputData.filePath,
|
|
352
378
|
};
|
|
353
379
|
const fileName = inputData.filePath.split( '/' );
|
|
@@ -371,6 +397,9 @@ export async function dowloadReport( req, res ) {
|
|
|
371
397
|
}
|
|
372
398
|
export async function sendReport( req, res ) {
|
|
373
399
|
try {
|
|
400
|
+
const bucket = JSON.parse( process.env.BUCKET );
|
|
401
|
+
const sqs = JSON.parse( process.env.SQS );
|
|
402
|
+
const sesConfig = JSON.parse( process.env.SES );
|
|
374
403
|
const inputData = req.body;
|
|
375
404
|
const getReportList = await findReport( { clientId: inputData.clientId } );
|
|
376
405
|
let reportName = [];
|
|
@@ -379,12 +408,12 @@ export async function sendReport( req, res ) {
|
|
|
379
408
|
let result = [];
|
|
380
409
|
let file = {};
|
|
381
410
|
let sendMailCount = 0;
|
|
382
|
-
let subject = '
|
|
411
|
+
let subject = 'Tango Eye\'s Customer Intelligence Report - ' + inputData.fileDate;
|
|
383
412
|
let messageBody = `<br>Hi Team,<br><br> Please find attached Tango RetailEye report on customer footfall and shopping patterns for ${inputData.fileDate}.<br><br> Thanks <br> Team Tango`;
|
|
384
413
|
let UserattachmentDetails = [];
|
|
385
414
|
for ( const data of getReportList ) {
|
|
386
415
|
const fetchData = {
|
|
387
|
-
Bucket:
|
|
416
|
+
Bucket: bucket.reportBucket,
|
|
388
417
|
Key: `${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/${inputData.fileDate}_${data.fileName}.${data.fileType}`,
|
|
389
418
|
};
|
|
390
419
|
reportName.push( `${inputData.fileDate}_${data.fileName}` );
|
|
@@ -419,7 +448,7 @@ export async function sendReport( req, res ) {
|
|
|
419
448
|
}
|
|
420
449
|
}
|
|
421
450
|
UserattachmentDetails.forEach( async ( userattach ) => {
|
|
422
|
-
await sendEmail( userattach.email, subject, messageBody, userattach.attachments,
|
|
451
|
+
await sendEmail( userattach.email, subject, messageBody, userattach.attachments, sesConfig.reportEmail ).then( ( response ) => {
|
|
423
452
|
result.push( response );
|
|
424
453
|
} );
|
|
425
454
|
} );
|
|
@@ -431,7 +460,7 @@ export async function sendReport( req, res ) {
|
|
|
431
460
|
return res.sendError( 'Forbiddon to Access', 403 );
|
|
432
461
|
}
|
|
433
462
|
const sqsProduceQueue = {
|
|
434
|
-
QueueUrl: `${
|
|
463
|
+
QueueUrl: `${sqs.url}${sqs.sendReport}`,
|
|
435
464
|
MessageBody: JSON.stringify( {
|
|
436
465
|
file_date: inputData.fileDate,
|
|
437
466
|
client_name: req.report?.reportConfigs?.reportName,
|
|
@@ -554,9 +583,10 @@ export async function updateBasePrice( req, res ) {
|
|
|
554
583
|
export async function sendEmail( toEmail, mailSubject, htmlBody, attachment, sourceEmail ) {
|
|
555
584
|
return new Promise( async ( resolve, reject ) => {
|
|
556
585
|
try {
|
|
586
|
+
const awsConfig = JSON.parse( process.env.AWS_CONFIG );
|
|
557
587
|
const ses = new aws.SES( {
|
|
558
588
|
apiVersion: 'latest',
|
|
559
|
-
region:
|
|
589
|
+
region: awsConfig.region,
|
|
560
590
|
// accessKeyId: process.env.AWS_ACCESS_KEY_ID_SES,
|
|
561
591
|
// secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY_SES,
|
|
562
592
|
} );
|
|
@@ -3,10 +3,10 @@ import express from 'express';
|
|
|
3
3
|
import { authorize, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
4
|
import { addReportValid, clientListTableValid, deleteReportValid, downloadReportValid, generateReportValid, getReportListValid, getReportLogValid, getReportValid, getSingleReportValid, sendReportValid, updateReportValid } from '../dtos/report.dtos.js';
|
|
5
5
|
import { clientReportList, createReport, deleteReport, dowloadReport, generateReport, getReport, getReportList, getReportLog, getSingleReport, sendReport, updateBasePrice, updateReport, uploadManualReport } from '../controllers/report.controllers.js';
|
|
6
|
-
import { isFileExist, isFolderExist, isReportEnable } from '../validations/report.validations.js';
|
|
6
|
+
import { isFileExist, isFolderExist, isReportEnable, isSendReportEnable } from '../validations/report.validations.js';
|
|
7
7
|
|
|
8
8
|
export const reportRouter = express.Router();
|
|
9
|
-
|
|
9
|
+
// report setting configurations
|
|
10
10
|
reportRouter.post( '/create-report/:id', isAllowedSessionHandler, authorize( { userType: [ 'tango' ], access: [
|
|
11
11
|
{ featureName: 'settings', name: 'configuration', permissions: [ 'isEdit' ] },
|
|
12
12
|
] } ), validate( addReportValid ), createReport );
|
|
@@ -29,43 +29,43 @@ reportRouter.get( '/delete-report/:id', isAllowedSessionHandler, authorize( { us
|
|
|
29
29
|
// admin report's overview
|
|
30
30
|
reportRouter.post( '/client-list-table', isAllowedSessionHandler,
|
|
31
31
|
authorize( { userType: [ 'tango' ], access: [
|
|
32
|
-
{ featureName: '
|
|
32
|
+
{ featureName: 'manage', name: 'reports', permissions: [ 'isView' ] },
|
|
33
33
|
] } ),
|
|
34
34
|
validate( clientListTableValid ), clientReportList );
|
|
35
35
|
|
|
36
36
|
reportRouter.post( '/generate-report', isAllowedSessionHandler,
|
|
37
37
|
authorize( { userType: [ 'tango' ], access: [
|
|
38
|
-
{ featureName: '
|
|
38
|
+
{ featureName: 'manage', name: 'reports', permissions: [ 'isEdit' ] },
|
|
39
39
|
] } ),
|
|
40
40
|
validate( generateReportValid ), isReportEnable, generateReport );
|
|
41
41
|
|
|
42
42
|
reportRouter.post( '/upload-manual-report', isAllowedSessionHandler,
|
|
43
43
|
authorize( { userType: [ 'tango' ], access: [
|
|
44
|
-
{ featureName: '
|
|
44
|
+
{ featureName: 'manage', name: 'reports', permissions: [ 'isEdit' ] },
|
|
45
45
|
] } ),
|
|
46
46
|
isReportEnable, uploadManualReport );
|
|
47
47
|
|
|
48
48
|
reportRouter.get( '/get-report-list', isAllowedSessionHandler,
|
|
49
49
|
authorize( { userType: [ 'tango' ], access: [
|
|
50
|
-
{ featureName: '
|
|
50
|
+
{ featureName: 'manage', name: 'reports', permissions: [ 'isView' ] },
|
|
51
51
|
] } ),
|
|
52
52
|
validate( getReportListValid ), isReportEnable, isFolderExist, getReportList );
|
|
53
53
|
|
|
54
54
|
reportRouter.get( '/download-report', isAllowedSessionHandler,
|
|
55
55
|
authorize( { userType: [ 'tango' ], access: [
|
|
56
|
-
{ featureName: '
|
|
56
|
+
{ featureName: 'manage', name: 'reports', permissions: [ 'isEdit' ] },
|
|
57
57
|
] } ),
|
|
58
|
-
validate( downloadReportValid ), isFileExist, dowloadReport );
|
|
58
|
+
validate( downloadReportValid ), isReportEnable, isFileExist, dowloadReport );
|
|
59
59
|
|
|
60
60
|
reportRouter.post( '/send-report', isAllowedSessionHandler,
|
|
61
61
|
authorize( { userType: [ 'tango' ], access: [
|
|
62
|
-
{ featureName: '
|
|
62
|
+
{ featureName: 'manage', name: 'reports', permissions: [ 'isEdit' ] },
|
|
63
63
|
] } ),
|
|
64
|
-
validate( sendReportValid ),
|
|
64
|
+
validate( sendReportValid ), isSendReportEnable, sendReport );
|
|
65
65
|
|
|
66
66
|
reportRouter.post( '/get-report-log', isAllowedSessionHandler,
|
|
67
67
|
authorize( { userType: [ 'tango' ], access: [
|
|
68
|
-
{ featureName: '
|
|
68
|
+
{ featureName: 'manage', name: 'reports', permissions: [ 'isView' ] },
|
|
69
69
|
] } ),
|
|
70
70
|
validate( getReportLogValid ), getReportLog );
|
|
71
71
|
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { checkFileExist, logger } from 'tango-app-api-middleware';
|
|
2
2
|
import { findOneClient } from '../service/client.service.js';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export async function isReportEnable( req, res, next ) {
|
|
6
|
+
try {
|
|
7
|
+
const inputData = req.method !== 'GET'? req.body: req.query;
|
|
8
|
+
const getReportName = await findOneClient( { 'clientId': inputData.clientId, 'status': { $in: [ 'active', 'hold' ] }, 'reportConfigs.report': true }, { '_id': 0, 'reportConfigs.reportName': 1, 'clientName': 1 } );
|
|
9
|
+
if ( !getReportName ) {
|
|
10
|
+
return res.sendError( 'This action was forbidden', 403 );
|
|
11
|
+
}
|
|
12
|
+
req.report = getReportName;
|
|
13
|
+
return next();
|
|
14
|
+
} catch ( error ) {
|
|
15
|
+
logger.error( { error: error, message: req.body, function: 'isReportEnable' } );
|
|
16
|
+
return res.sendError( error, 500 );
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function isSendReportEnable( req, res, next ) {
|
|
6
21
|
try {
|
|
7
22
|
const inputData = req.method !== 'GET'? req.body: req.query;
|
|
8
23
|
const getReportName = await findOneClient( { 'clientId': inputData.clientId, 'status': 'active', 'reportConfigs.report': true }, { '_id': 0, 'reportConfigs.reportName': 1, 'clientName': 1 } );
|
|
9
24
|
if ( !getReportName ) {
|
|
10
|
-
return res.sendError( '
|
|
25
|
+
return res.sendError( 'This action was forbidden', 403 );
|
|
11
26
|
}
|
|
12
27
|
req.report = getReportName;
|
|
13
28
|
return next();
|
|
@@ -19,9 +34,10 @@ export async function isReportEnable( req, res, next ) {
|
|
|
19
34
|
|
|
20
35
|
export async function isFolderExist( req, res, next ) {
|
|
21
36
|
try {
|
|
37
|
+
const bucket = JSON.parse( process.env.BUCKET );
|
|
22
38
|
const inputData = req.query;
|
|
23
39
|
const fetchData = {
|
|
24
|
-
Bucket:
|
|
40
|
+
Bucket: bucket.reportBucket,
|
|
25
41
|
Key: `${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
|
|
26
42
|
};
|
|
27
43
|
logger.info( { fetchData: fetchData, report: req.report?.reportConfigs?.reportName } );
|
|
@@ -39,9 +55,10 @@ export async function isFolderExist( req, res, next ) {
|
|
|
39
55
|
|
|
40
56
|
export async function isFileExist( req, res, next ) {
|
|
41
57
|
try {
|
|
58
|
+
const bucket = JSON.parse( process.env.BUCKET );
|
|
42
59
|
const inputData = req.query;
|
|
43
60
|
const fetchData = {
|
|
44
|
-
Bucket:
|
|
61
|
+
Bucket: bucket.reportBucket,
|
|
45
62
|
Key: inputData.Key,
|
|
46
63
|
};
|
|
47
64
|
const isExist = await checkFileExist( fetchData );
|