tango-app-api-report 3.5.0 → 3.5.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.5.
|
|
3
|
+
"version": "3.5.2",
|
|
4
4
|
"description": "report",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
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.4.
|
|
28
|
+
"tango-api-schema": "^2.4.30",
|
|
29
29
|
"tango-app-api-middleware": "^3.1.45",
|
|
30
30
|
"winston": "^3.12.0",
|
|
31
31
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkFileExist, logger } from 'tango-app-api-middleware';
|
|
1
|
+
import { checkFileExist, insertOpenSearchData, logger } from 'tango-app-api-middleware';
|
|
2
2
|
import { findOneClient } from '../service/client.service.js';
|
|
3
3
|
import { aggregateStoreAudit } from '../service/storeAudit.service.js';
|
|
4
4
|
import { getQueueUrl, receiveMessage } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
@@ -8,10 +8,45 @@ import axios from 'axios';
|
|
|
8
8
|
export async function isReportEnable( req, res, next ) {
|
|
9
9
|
try {
|
|
10
10
|
const inputData = req.method !== 'GET'? req.body: req.query;
|
|
11
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
11
12
|
const getReportName = await findOneClient( { 'clientId': inputData.clientId, 'status': { $in: [ 'active', 'hold' ] }, 'reportConfigs.report': true }, { '_id': 0, 'reportConfigs': 1, 'clientName': 1, 'auditConfigs': 1 } );
|
|
12
13
|
if ( !getReportName ) {
|
|
14
|
+
const logErr = {
|
|
15
|
+
userName: req.user.userName,
|
|
16
|
+
userId: req.user._id,
|
|
17
|
+
logType: 'reportLog',
|
|
18
|
+
logSubType: 'generateReportLog',
|
|
19
|
+
logData: {
|
|
20
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
21
|
+
reportName: getReportName?.reportConfigs?.reportName || '',
|
|
22
|
+
clientId: inputData?.clientId || '',
|
|
23
|
+
reportType: getReportName?.reportConfigs?.reportType ||'',
|
|
24
|
+
message: 'get-report-config-err',
|
|
25
|
+
infoType: 'error',
|
|
26
|
+
},
|
|
27
|
+
createdAt: Date.now(),
|
|
28
|
+
};
|
|
29
|
+
await insertOpenSearchData( openSearch?.auditLog, logErr );
|
|
30
|
+
|
|
13
31
|
return res.sendError( 'This action was forbidden', 403 );
|
|
14
32
|
}
|
|
33
|
+
const logInfo = {
|
|
34
|
+
userName: req.user.userName,
|
|
35
|
+
userId: req.user._id,
|
|
36
|
+
logType: 'reportLog',
|
|
37
|
+
logSubType: 'generateReportLog',
|
|
38
|
+
logData: {
|
|
39
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
40
|
+
reportName: getReportName?.reportConfigs?.reportName,
|
|
41
|
+
clientId: inputData?.clientId,
|
|
42
|
+
reportType: getReportName?.reportConfigs?.reportType,
|
|
43
|
+
message: 'get-report-config-info',
|
|
44
|
+
infoType: 'info',
|
|
45
|
+
},
|
|
46
|
+
createdAt: Date.now(),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
await insertOpenSearchData( openSearch?.auditLog, logInfo );
|
|
15
50
|
req.report = getReportName;
|
|
16
51
|
return next();
|
|
17
52
|
} catch ( error ) {
|
|
@@ -82,6 +117,7 @@ export async function isFileExist( req, res, next ) {
|
|
|
82
117
|
export async function isAuditCompleted( req, res, next ) {
|
|
83
118
|
try {
|
|
84
119
|
const inputData = req.body;
|
|
120
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
85
121
|
if ( req?.report?.reportConfigs?.reportType !== 'manual' ) {
|
|
86
122
|
logger.info( { inputData: inputData } );
|
|
87
123
|
|
|
@@ -115,7 +151,44 @@ export async function isAuditCompleted( req, res, next ) {
|
|
|
115
151
|
];
|
|
116
152
|
|
|
117
153
|
const getStoreAudit = await aggregateStoreAudit( getStoreAuditQuery );
|
|
154
|
+
const logInfo = {
|
|
155
|
+
userName: req.user.userName,
|
|
156
|
+
userId: req.user._id,
|
|
157
|
+
logType: 'reportLog',
|
|
158
|
+
logSubType: 'generateReportLog',
|
|
159
|
+
logData: {
|
|
160
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
161
|
+
reportName: req?.report?.reportConfigs?.reportName,
|
|
162
|
+
clientId: inputData?.clientId,
|
|
163
|
+
reportType: req?.report?.reportConfigs?.reportType,
|
|
164
|
+
message: 'get-audit-store-count-info',
|
|
165
|
+
storeAuditData: JSON.stringify( getStoreAudit ),
|
|
166
|
+
length: getStoreAudit?.[0]?.storeId?.length || 0,
|
|
167
|
+
infoType: 'info',
|
|
168
|
+
},
|
|
169
|
+
createdAt: Date.now(),
|
|
170
|
+
};
|
|
171
|
+
await insertOpenSearchData( openSearch?.auditLog, logInfo );
|
|
118
172
|
if ( getStoreAudit && getStoreAudit?.[0]?.storeId?.length >0 ) {
|
|
173
|
+
const logErr = {
|
|
174
|
+
userName: req.user.userName,
|
|
175
|
+
userId: req.user._id,
|
|
176
|
+
logType: 'reportLog',
|
|
177
|
+
logSubType: 'generateReportLog',
|
|
178
|
+
logData: {
|
|
179
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
180
|
+
reportName: req?.report?.reportConfigs?.reportName,
|
|
181
|
+
clientId: inputData?.clientId,
|
|
182
|
+
reportType: req?.report?.reportConfigs?.reportType,
|
|
183
|
+
message: 'get-audit-audit-count-err',
|
|
184
|
+
storeAuditData: JSON.stringify( getStoreAudit ),
|
|
185
|
+
length: getStoreAudit?.[0]?.storeId?.length || 0,
|
|
186
|
+
infoType: 'error',
|
|
187
|
+
},
|
|
188
|
+
createdAt: Date.now(),
|
|
189
|
+
};
|
|
190
|
+
await insertOpenSearchData( openSearch?.auditLog, logErr );
|
|
191
|
+
logger.info( { logErr } );
|
|
119
192
|
return res.sendError(
|
|
120
193
|
'Some files are not completed in the audit level for the selected date. Please try again later.',
|
|
121
194
|
400,
|
|
@@ -136,6 +209,8 @@ export async function isAuditCompleted( req, res, next ) {
|
|
|
136
209
|
// -----------------------------
|
|
137
210
|
export async function getQueueCount( req, res, next ) {
|
|
138
211
|
try {
|
|
212
|
+
const inputData = req.body;
|
|
213
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
139
214
|
if ( req?.report?.reportConfigs?.reportType !== 'manual' ) {
|
|
140
215
|
if ( !req?.report?.auditConfigs ) return next();
|
|
141
216
|
|
|
@@ -159,8 +234,41 @@ export async function getQueueCount( req, res, next ) {
|
|
|
159
234
|
|
|
160
235
|
// Run all enabled checks, stop on first true
|
|
161
236
|
const isProcessing = await runQueueChecks( auditConfig, queueChecks );
|
|
162
|
-
|
|
237
|
+
const logInfo = {
|
|
238
|
+
userName: req.user.userName,
|
|
239
|
+
userId: req.user._id,
|
|
240
|
+
logType: 'reportLog',
|
|
241
|
+
logSubType: 'generateReportLog',
|
|
242
|
+
logData: {
|
|
243
|
+
fileDate: inputData?.fileDate?.split( '-' ).reverse().join( '-' ),
|
|
244
|
+
reportName: req?.report?.reportConfigs?.reportName,
|
|
245
|
+
clientId: inputData?.clientId,
|
|
246
|
+
reportType: req?.report?.reportConfigs?.reportType,
|
|
247
|
+
message: 'get-audit-queue-count-info',
|
|
248
|
+
isProcessing: isProcessing,
|
|
249
|
+
infoType: 'info',
|
|
250
|
+
},
|
|
251
|
+
createdAt: Date.now(),
|
|
252
|
+
};
|
|
253
|
+
await insertOpenSearchData( openSearch?.auditLog, logInfo );
|
|
163
254
|
if ( isProcessing ) {
|
|
255
|
+
const logErr = {
|
|
256
|
+
userName: req.user.userName,
|
|
257
|
+
userId: req.user._id,
|
|
258
|
+
logType: 'reportLog',
|
|
259
|
+
logSubType: 'generateReportLog',
|
|
260
|
+
logData: {
|
|
261
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
262
|
+
reportName: req?.report?.reportConfigs?.reportName,
|
|
263
|
+
clientId: inputData?.clientId,
|
|
264
|
+
reportType: req?.report?.reportConfigs?.reportType,
|
|
265
|
+
message: 'get-audit-queue-count-err',
|
|
266
|
+
isProcessing: isProcessing,
|
|
267
|
+
infoType: 'error',
|
|
268
|
+
},
|
|
269
|
+
createdAt: Date.now(),
|
|
270
|
+
};
|
|
271
|
+
await insertOpenSearchData( openSearch?.auditLog, logErr );
|
|
164
272
|
return res.sendError(
|
|
165
273
|
'This client is already being processed in the Queue. Please try again later.',
|
|
166
274
|
400,
|
|
@@ -242,18 +350,93 @@ export async function isFeatureRunning( req, res, next ) {
|
|
|
242
350
|
const inputData = req.body;
|
|
243
351
|
if ( req?.report?.reportConfigs?.reportType !== 'manual' ) {
|
|
244
352
|
const url = JSON.parse( process.env.URL );
|
|
353
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
245
354
|
const REIDURL = url.REIDStatus;
|
|
246
355
|
const FeatureURL = url.FeatureStatus;
|
|
247
|
-
const data = { 'client_id': inputData.clientId, 'store_date': inputData?.fileDate };
|
|
356
|
+
const data = { 'client_id': inputData.clientId, 'store_date': inputData?.fileDate.split( '-' ).reverse().join( '-' ) };
|
|
248
357
|
|
|
249
358
|
const isFeature = await callLambdaWithData( data, FeatureURL );
|
|
359
|
+
const logInfo = {
|
|
360
|
+
userName: req.user.userName,
|
|
361
|
+
userId: req.user._id,
|
|
362
|
+
logType: 'reportLog',
|
|
363
|
+
logSubType: 'generateReportLog',
|
|
364
|
+
logData: {
|
|
365
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
366
|
+
reportName: req?.report?.reportConfigs?.reportName,
|
|
367
|
+
clientId: inputData?.clientId,
|
|
368
|
+
reportType: req?.report?.reportConfigs?.reportType,
|
|
369
|
+
message: 'get-feature-count-info',
|
|
370
|
+
isFeatureData: JSON.stringify( isFeature ),
|
|
371
|
+
infoType: 'info',
|
|
372
|
+
},
|
|
373
|
+
createdAt: Date.now(),
|
|
374
|
+
};
|
|
375
|
+
await insertOpenSearchData( openSearch?.auditLog, logInfo );
|
|
250
376
|
const isREID = await callLambdaWithData( data, REIDURL );
|
|
377
|
+
const logReid = {
|
|
378
|
+
userName: req.user.userName,
|
|
379
|
+
userId: req.user._id,
|
|
380
|
+
logType: 'reportLog',
|
|
381
|
+
logSubType: 'generateReportLog',
|
|
382
|
+
logData: {
|
|
383
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
384
|
+
reportName: req?.report?.reportConfigs?.reportName,
|
|
385
|
+
clientId: inputData?.clientId,
|
|
386
|
+
reportType: req?.report?.reportConfigs?.reportType,
|
|
387
|
+
message: 'get-reid-count-info',
|
|
388
|
+
reidData: JSON.stringify( isREID ),
|
|
389
|
+
infoType: 'info',
|
|
390
|
+
},
|
|
391
|
+
createdAt: Date.now(),
|
|
392
|
+
};
|
|
393
|
+
await insertOpenSearchData( openSearch?.auditLog, logReid );
|
|
251
394
|
if ( isFeature?.status_code !== '200' ||isREID?.status_code !== '200' ) {
|
|
395
|
+
const logErr = {
|
|
396
|
+
userName: req.user.userName,
|
|
397
|
+
userId: req.user._id,
|
|
398
|
+
logType: 'reportLog',
|
|
399
|
+
logSubType: 'generateReportLog',
|
|
400
|
+
logData: {
|
|
401
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
402
|
+
reportName: req?.report?.reportConfigs?.reportName,
|
|
403
|
+
clientId: inputData?.clientId,
|
|
404
|
+
reportType: req?.report?.reportConfigs?.reportType,
|
|
405
|
+
message: 'get-feature-reid-code-err',
|
|
406
|
+
|
|
407
|
+
featureData: JSON.stringify( isFeature ),
|
|
408
|
+
reidData: JSON.stringify( isREID ),
|
|
409
|
+
|
|
410
|
+
infoType: 'error',
|
|
411
|
+
},
|
|
412
|
+
createdAt: Date.now(),
|
|
413
|
+
};
|
|
414
|
+
await insertOpenSearchData( openSearch?.auditLog, logErr );
|
|
252
415
|
return res.sendError(
|
|
253
416
|
'This client is already being processed in REID/Feature layer for the selected date. Please try again later.',
|
|
254
417
|
400,
|
|
255
418
|
);
|
|
256
419
|
} else if ( isFeature?.data === false || isREID?.data === false ) {
|
|
420
|
+
const logBooErr = {
|
|
421
|
+
userName: req.user.userName,
|
|
422
|
+
userId: req.user._id,
|
|
423
|
+
logType: 'reportLog',
|
|
424
|
+
logSubType: 'generateReportLog',
|
|
425
|
+
logData: {
|
|
426
|
+
fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
|
|
427
|
+
reportName: req?.report?.reportConfigs?.reportName,
|
|
428
|
+
clientId: inputData?.clientId,
|
|
429
|
+
reportType: req?.report?.reportConfigs?.reportType,
|
|
430
|
+
message: 'get-feature-reid-boolean-err',
|
|
431
|
+
|
|
432
|
+
featureData: JSON.stringify( isFeature ),
|
|
433
|
+
reidData: JSON.stringify( isREID ),
|
|
434
|
+
|
|
435
|
+
infoType: 'error',
|
|
436
|
+
},
|
|
437
|
+
createdAt: Date.now(),
|
|
438
|
+
};
|
|
439
|
+
await insertOpenSearchData( openSearch?.auditLog, logBooErr );
|
|
257
440
|
return res.sendError(
|
|
258
441
|
'This client is already being processed in REID/Feature layer for the selected date. Please try again later.',
|
|
259
442
|
400,
|
|
@@ -266,7 +449,7 @@ export async function isFeatureRunning( req, res, next ) {
|
|
|
266
449
|
}
|
|
267
450
|
} catch ( error ) {
|
|
268
451
|
logger.error( { error: error, message: req.query, function: 'isFeatureRunning' } );
|
|
269
|
-
return res.sendError( error.message || '
|
|
452
|
+
return res.sendError( error.message || 'Internal Server Error', 500 );
|
|
270
453
|
}
|
|
271
454
|
}
|
|
272
455
|
|