tango-app-api-report 3.1.3 → 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
|
},
|
|
@@ -130,7 +130,6 @@ export async function clientReportList( req, res ) {
|
|
|
130
130
|
$match: {
|
|
131
131
|
$and: [
|
|
132
132
|
{ 'reportConfigs.report': { $eq: true } },
|
|
133
|
-
{ status: { $eq: 'active' } },
|
|
134
133
|
{ clientId: { $in: inputData.clientId } },
|
|
135
134
|
],
|
|
136
135
|
|
|
@@ -141,6 +140,7 @@ export async function clientReportList( req, res ) {
|
|
|
141
140
|
clientId: 1,
|
|
142
141
|
tangoId: 1,
|
|
143
142
|
clientName: 1,
|
|
143
|
+
status: 1,
|
|
144
144
|
daysDifference: 1,
|
|
145
145
|
datesArray: {
|
|
146
146
|
$map: {
|
|
@@ -166,6 +166,21 @@ export async function clientReportList( req, res ) {
|
|
|
166
166
|
clientName: 1,
|
|
167
167
|
tangoId: 1,
|
|
168
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
|
+
},
|
|
169
184
|
},
|
|
170
185
|
},
|
|
171
186
|
];
|
|
@@ -196,6 +211,10 @@ export async function clientReportList( req, res ) {
|
|
|
196
211
|
clientId: { $regex: inputData.searchValue, $options: 'i' },
|
|
197
212
|
|
|
198
213
|
},
|
|
214
|
+
{
|
|
215
|
+
status: { $regex: inputData.searchValue, $options: 'i' },
|
|
216
|
+
|
|
217
|
+
},
|
|
199
218
|
],
|
|
200
219
|
},
|
|
201
220
|
},
|
|
@@ -223,6 +242,7 @@ export async function clientReportList( req, res ) {
|
|
|
223
242
|
export async function generateReport( req, res ) {
|
|
224
243
|
try {
|
|
225
244
|
const sqs = JSON.parse( process.env.SQS );
|
|
245
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
226
246
|
const inputData = req.body;
|
|
227
247
|
const sqsProduceQueue = {
|
|
228
248
|
QueueUrl: `${sqs.url}${sqs.generateReport}`,
|
|
@@ -249,7 +269,7 @@ export async function generateReport( req, res ) {
|
|
|
249
269
|
sqsMessageId: sqsQueue.MessageId,
|
|
250
270
|
},
|
|
251
271
|
};
|
|
252
|
-
await insertOpenSearchData(
|
|
272
|
+
await insertOpenSearchData( openSearch.activityLog, log );
|
|
253
273
|
|
|
254
274
|
return res.sendSuccess( { result: 'Report has been Initiated Sucessfully' } );
|
|
255
275
|
}
|
|
@@ -388,7 +408,7 @@ export async function sendReport( req, res ) {
|
|
|
388
408
|
let result = [];
|
|
389
409
|
let file = {};
|
|
390
410
|
let sendMailCount = 0;
|
|
391
|
-
let subject = '
|
|
411
|
+
let subject = 'Tango Eye\'s Customer Intelligence Report - ' + inputData.fileDate;
|
|
392
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`;
|
|
393
413
|
let UserattachmentDetails = [];
|
|
394
414
|
for ( const data of getReportList ) {
|
|
@@ -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
|
|
|
@@ -3,11 +3,26 @@ 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();
|