tango-app-api-report 3.5.2 → 3.5.4

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.2",
3
+ "version": "3.5.4",
4
4
  "description": "report",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -118,40 +118,57 @@ export async function isAuditCompleted( req, res, next ) {
118
118
  try {
119
119
  const inputData = req.body;
120
120
  const openSearch = JSON.parse( process.env.OPENSEARCH );
121
- if ( req?.report?.reportConfigs?.reportType !== 'manual' ) {
122
- logger.info( { inputData: inputData } );
123
-
124
- const getStoreAuditQuery = [
125
- {
126
- $match: {
127
- $and: [
128
- {
129
- fileDate: { $eq: inputData.fileDate },
130
- },
131
- {
132
- clientId: { $eq: inputData.clientId },
133
- },
134
- {
135
- status: { $ne: 'completed' },
136
- },
137
- ],
138
- },
121
+
122
+ const getStoreAuditQuery = [
123
+ {
124
+ $match: {
125
+ $and: [
126
+ {
127
+ fileDate: { $eq: inputData?.fileDate.split( '-' ).reverse().join( '-' ) },
128
+ },
129
+ {
130
+ clientId: { $eq: inputData.clientId },
131
+ },
132
+ {
133
+ status: { $ne: 'completed' },
134
+ },
135
+ ],
139
136
  },
140
- {
141
- $group: {
142
- _id: null,
143
- storeId: { $addToSet: '$storeId' },
144
- },
137
+ },
138
+ {
139
+ $group: {
140
+ _id: null,
141
+ storeId: { $addToSet: '$storeId' },
145
142
  },
146
- {
147
- $project: {
148
- storeId: 1,
149
- },
143
+ },
144
+ {
145
+ $project: {
146
+ storeId: 1,
150
147
  },
151
- ];
148
+ },
149
+ ];
152
150
 
153
- const getStoreAudit = await aggregateStoreAudit( getStoreAuditQuery );
154
- const logInfo = {
151
+ const getStoreAudit = await aggregateStoreAudit( getStoreAuditQuery );
152
+ const logInfo = {
153
+ userName: req.user.userName,
154
+ userId: req.user._id,
155
+ logType: 'reportLog',
156
+ logSubType: 'generateReportLog',
157
+ logData: {
158
+ fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
159
+ reportName: req?.report?.reportConfigs?.reportName,
160
+ clientId: inputData?.clientId,
161
+ reportType: req?.report?.reportConfigs?.reportType,
162
+ message: 'get-audit-store-count-info',
163
+ storeAuditData: JSON.stringify( getStoreAudit ),
164
+ length: getStoreAudit?.[0]?.storeId?.length || 0,
165
+ infoType: 'info',
166
+ },
167
+ createdAt: Date.now(),
168
+ };
169
+ await insertOpenSearchData( openSearch?.auditLog, logInfo );
170
+ if ( getStoreAudit && getStoreAudit?.[0]?.storeId?.length >0 ) {
171
+ const logErr = {
155
172
  userName: req.user.userName,
156
173
  userId: req.user._id,
157
174
  logType: 'reportLog',
@@ -161,41 +178,19 @@ export async function isAuditCompleted( req, res, next ) {
161
178
  reportName: req?.report?.reportConfigs?.reportName,
162
179
  clientId: inputData?.clientId,
163
180
  reportType: req?.report?.reportConfigs?.reportType,
164
- message: 'get-audit-store-count-info',
181
+ message: 'get-audit-audit-count-err',
165
182
  storeAuditData: JSON.stringify( getStoreAudit ),
166
183
  length: getStoreAudit?.[0]?.storeId?.length || 0,
167
- infoType: 'info',
184
+ infoType: 'error',
168
185
  },
169
186
  createdAt: Date.now(),
170
187
  };
171
- await insertOpenSearchData( openSearch?.auditLog, logInfo );
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 } );
192
- return res.sendError(
193
- 'Some files are not completed in the audit level for the selected date. Please try again later.',
194
- 400,
195
- );
196
- } else {
197
- return next();
198
- }
188
+ await insertOpenSearchData( openSearch?.auditLog, logErr );
189
+ logger.info( { logErr } );
190
+ return res.sendError(
191
+ 'Some files are not completed in the audit level for the selected date. Please try again later.',
192
+ 400,
193
+ );
199
194
  } else {
200
195
  return next();
201
196
  }
@@ -211,74 +206,71 @@ export async function getQueueCount( req, res, next ) {
211
206
  try {
212
207
  const inputData = req.body;
213
208
  const openSearch = JSON.parse( process.env.OPENSEARCH );
214
- if ( req?.report?.reportConfigs?.reportType !== 'manual' ) {
215
- if ( !req?.report?.auditConfigs ) return next();
216
209
 
217
- const temp = req.report.auditConfigs;
210
+ if ( !req?.report?.auditConfigs ) return next();
218
211
 
219
- // Config flags
220
- const auditConfig = {
221
- track: temp.audit,
222
- traffic: temp.trackAudit,
223
- };
212
+ const temp = req.report.auditConfigs;
224
213
 
214
+ // Config flags
215
+ const auditConfig = {
216
+ track: temp.audit,
217
+ traffic: temp.trackAudit,
218
+ };
225
219
 
226
- // Mapping of config flags to queue-check functions
227
- const queueChecks = {
228
- track: [ () => checkTrackingQueueCount( temp?.trackQueueName ) ],
229
- traffic: [
230
- () => checkTrafficQueueCount( temp?.trafficQueueName ),
231
- () => checkZoneQueueCount( temp?.zoneQueueName ),
232
- ],
233
- };
234
220
 
235
- // Run all enabled checks, stop on first true
236
- const isProcessing = await runQueueChecks( auditConfig, queueChecks );
237
- const logInfo = {
221
+ // Mapping of config flags to queue-check functions
222
+ const queueChecks = {
223
+ track: [ () => checkTrackingQueueCount( temp?.trackQueueName ) ],
224
+ traffic: [
225
+ () => checkTrafficQueueCount( temp?.trafficQueueName ),
226
+ () => checkZoneQueueCount( temp?.zoneQueueName ),
227
+ ],
228
+ };
229
+
230
+ // Run all enabled checks, stop on first true
231
+ const isProcessing = await runQueueChecks( auditConfig, queueChecks );
232
+ const logInfo = {
233
+ userName: req.user.userName,
234
+ userId: req.user._id,
235
+ logType: 'reportLog',
236
+ logSubType: 'generateReportLog',
237
+ logData: {
238
+ fileDate: inputData?.fileDate?.split( '-' ).reverse().join( '-' ),
239
+ reportName: req?.report?.reportConfigs?.reportName,
240
+ clientId: inputData?.clientId,
241
+ reportType: req?.report?.reportConfigs?.reportType,
242
+ message: 'get-audit-queue-count-info',
243
+ isProcessing: isProcessing,
244
+ infoType: 'info',
245
+ },
246
+ createdAt: Date.now(),
247
+ };
248
+ await insertOpenSearchData( openSearch?.auditLog, logInfo );
249
+ if ( isProcessing ) {
250
+ const logErr = {
238
251
  userName: req.user.userName,
239
252
  userId: req.user._id,
240
253
  logType: 'reportLog',
241
254
  logSubType: 'generateReportLog',
242
255
  logData: {
243
- fileDate: inputData?.fileDate?.split( '-' ).reverse().join( '-' ),
256
+ fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
244
257
  reportName: req?.report?.reportConfigs?.reportName,
245
258
  clientId: inputData?.clientId,
246
259
  reportType: req?.report?.reportConfigs?.reportType,
247
- message: 'get-audit-queue-count-info',
260
+ message: 'get-audit-queue-count-err',
248
261
  isProcessing: isProcessing,
249
- infoType: 'info',
262
+ infoType: 'error',
250
263
  },
251
264
  createdAt: Date.now(),
252
265
  };
253
- await insertOpenSearchData( openSearch?.auditLog, logInfo );
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 );
272
- return res.sendError(
273
- 'This client is already being processed in the Queue. Please try again later.',
274
- 400,
275
- );
276
- }
277
-
278
- return next();
279
- } else {
280
- return next();
266
+ await insertOpenSearchData( openSearch?.auditLog, logErr );
267
+ return res.sendError(
268
+ 'This client is already being processed in the Queue. Please try again later.',
269
+ 400,
270
+ );
281
271
  }
272
+
273
+ return next();
282
274
  } catch ( error ) {
283
275
  logger.error( { error, message: req.body, function: 'getQueueCount' } );
284
276
  return res.sendError( error.message || 'Internal Server Error', 500 );
@@ -348,15 +340,72 @@ async function checkZoneQueueCount( queueName ) {
348
340
  export async function isFeatureRunning( req, res, next ) {
349
341
  try {
350
342
  const inputData = req.body;
351
- if ( req?.report?.reportConfigs?.reportType !== 'manual' ) {
352
- const url = JSON.parse( process.env.URL );
353
- const openSearch = JSON.parse( process.env.OPENSEARCH );
354
- const REIDURL = url.REIDStatus;
355
- const FeatureURL = url.FeatureStatus;
356
- const data = { 'client_id': inputData.clientId, 'store_date': inputData?.fileDate.split( '-' ).reverse().join( '-' ) };
357
-
358
- const isFeature = await callLambdaWithData( data, FeatureURL );
359
- const logInfo = {
343
+
344
+ const url = JSON.parse( process.env.URL );
345
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
346
+ const REIDURL = url.REIDStatus;
347
+ const FeatureURL = url.FeatureStatus;
348
+ const downTimeURL = url.ReportDowntimeCheck;
349
+ const data = { 'client_id': inputData.clientId, 'store_date': inputData?.fileDate.split( '-' ).reverse().join( '-' ) };
350
+ const downTimeData = { 'clientId': inputData.clientId, 'date': inputData?.fileDate.split( '-' ).reverse().join( '-' ) };
351
+ const isREID = await callLambdaWithData( data, REIDURL );
352
+ const logReid = {
353
+ userName: req.user.userName,
354
+ userId: req.user._id,
355
+ logType: 'reportLog',
356
+ logSubType: 'generateReportLog',
357
+ logData: {
358
+ fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
359
+ reportName: req?.report?.reportConfigs?.reportName,
360
+ clientId: inputData?.clientId,
361
+ reportType: req?.report?.reportConfigs?.reportType,
362
+ message: 'get-reid-count-info',
363
+ reidData: JSON.stringify( isREID ),
364
+ infoType: 'info',
365
+ },
366
+ createdAt: Date.now(),
367
+ };
368
+ await insertOpenSearchData( openSearch?.auditLog, logReid );
369
+ const isFeature = await callLambdaWithData( data, FeatureURL );
370
+ const logInfo = {
371
+ userName: req.user.userName,
372
+ userId: req.user._id,
373
+ logType: 'reportLog',
374
+ logSubType: 'generateReportLog',
375
+ logData: {
376
+ fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
377
+ reportName: req?.report?.reportConfigs?.reportName,
378
+ clientId: inputData?.clientId,
379
+ reportType: req?.report?.reportConfigs?.reportType,
380
+ message: 'get-feature-count-info',
381
+ isFeatureData: JSON.stringify( isFeature ),
382
+ infoType: 'info',
383
+ },
384
+ createdAt: Date.now(),
385
+ };
386
+ await insertOpenSearchData( openSearch?.auditLog, logInfo );
387
+
388
+
389
+ const isDownTimeCheck = await callLambdaWithData( downTimeData, downTimeURL );
390
+ const logDownTimeCheck = {
391
+ userName: req.user.userName,
392
+ userId: req.user._id,
393
+ logType: 'reportLog',
394
+ logSubType: 'generateReportLog',
395
+ logData: {
396
+ fileDate: inputData?.fileDate.split( '-' ).reverse().join( '-' ),
397
+ reportName: req?.report?.reportConfigs?.reportName,
398
+ clientId: inputData?.clientId,
399
+ reportType: req?.report?.reportConfigs?.reportType,
400
+ message: 'get-down-time',
401
+ reidData: JSON.stringify( isREID ),
402
+ infoType: 'info',
403
+ },
404
+ createdAt: Date.now(),
405
+ };
406
+ await insertOpenSearchData( openSearch?.auditLog, logDownTimeCheck );
407
+ if ( isFeature?.status_code !== '200' ||isREID?.status_code !== '200' || isDownTimeCheck?.status_code !== '200' ) {
408
+ const logErr = {
360
409
  userName: req.user.userName,
361
410
  userId: req.user._id,
362
411
  logType: 'reportLog',
@@ -366,15 +415,22 @@ export async function isFeatureRunning( req, res, next ) {
366
415
  reportName: req?.report?.reportConfigs?.reportName,
367
416
  clientId: inputData?.clientId,
368
417
  reportType: req?.report?.reportConfigs?.reportType,
369
- message: 'get-feature-count-info',
370
- isFeatureData: JSON.stringify( isFeature ),
371
- infoType: 'info',
418
+ message: isDownTimeCheck?.status_code !== '200'? 'get-down-time':'get-feature-reid-code-err',
419
+ featureData: JSON.stringify( isFeature ),
420
+ reidData: JSON.stringify( isREID ),
421
+ isDownTimeCheck: JSON.stringify( isDownTimeCheck ),
422
+
423
+ infoType: 'error',
372
424
  },
373
425
  createdAt: Date.now(),
374
426
  };
375
- await insertOpenSearchData( openSearch?.auditLog, logInfo );
376
- const isREID = await callLambdaWithData( data, REIDURL );
377
- const logReid = {
427
+ await insertOpenSearchData( openSearch?.auditLog, logErr );
428
+ return res.sendError(
429
+ 'This client is already being processed in REID/Feature layer for the selected date. Please try again later.',
430
+ 400,
431
+ );
432
+ } else if ( isFeature?.data === false || isREID?.data === false || isDownTimeCheck?.data === false ) {
433
+ const logBooErr = {
378
434
  userName: req.user.userName,
379
435
  userId: req.user._id,
380
436
  logType: 'reportLog',
@@ -384,66 +440,20 @@ export async function isFeatureRunning( req, res, next ) {
384
440
  reportName: req?.report?.reportConfigs?.reportName,
385
441
  clientId: inputData?.clientId,
386
442
  reportType: req?.report?.reportConfigs?.reportType,
387
- message: 'get-reid-count-info',
443
+ message: isDownTimeCheck?.data === false ? 'get-down-time' : 'get-feature-reid-boolean-err',
444
+
445
+ featureData: JSON.stringify( isFeature ),
388
446
  reidData: JSON.stringify( isREID ),
389
- infoType: 'info',
447
+ isDownTimeCheck: JSON.stringify( isDownTimeCheck ),
448
+ infoType: 'error',
390
449
  },
391
450
  createdAt: Date.now(),
392
451
  };
393
- await insertOpenSearchData( openSearch?.auditLog, logReid );
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 );
415
- return res.sendError(
416
- 'This client is already being processed in REID/Feature layer for the selected date. Please try again later.',
417
- 400,
418
- );
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 );
440
- return res.sendError(
441
- 'This client is already being processed in REID/Feature layer for the selected date. Please try again later.',
442
- 400,
443
- );
444
- } else {
445
- return next();
446
- }
452
+ await insertOpenSearchData( openSearch?.auditLog, logBooErr );
453
+ return res.sendError(
454
+ isDownTimeCheck?.data === false? 'Downtime error, please looking the teams alert for further details':'This client is already being processed in REID/Feature layer for the selected date. Please try again later.',
455
+ 400,
456
+ );
447
457
  } else {
448
458
  return next();
449
459
  }