tango-app-api-audit 3.5.61 → 3.6.1

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-audit",
3
- "version": "3.5.61",
3
+ "version": "3.6.1",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  import express from 'express';
2
- import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, validateUserAudit, validation } from '../validation/audit.validation.js';
2
+ import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, isFeatureRunning, validateUserAudit, validation } from '../validation/audit.validation.js';
3
3
  import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
4
  import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs, getUserCredit, rePushAuditStores } from '../controllers/audit.controllers.js';
5
5
  import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid, auditViewLogValid, rePushAuditStoresValid } from '../dtos/audit.dtos.js';
@@ -28,7 +28,7 @@ auditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, acc
28
28
  auditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( overAllAuditSummaryValid ), overAllAuditSummary );
29
29
  auditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler,
30
30
  accessVerification( { userType: [ 'tango' ], access: [ { featureName: 'TangoAdmin', name: 'TicketConfiguration', permissions: [ 'isEdit' ] } ] } ),
31
- validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
31
+ validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, isFeatureRunning, reTrigger );
32
32
  auditRouter.get( '/audit-images', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditImageValid ), isAuditInputFolderExist, auditImages );
33
33
  // summary
34
34
  auditRouter.post( '/metrics/overview-card', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( overViewCardValid ), overViewCard );
@@ -1,4 +1,4 @@
1
- import { checkFileExist, chunkArray, getJsonFileData, getObject, getQueueUrl, insertWithId, listFileWithoutLimit, logger, signedUrl } from 'tango-app-api-middleware';
1
+ import { checkFileExist, chunkArray, getJsonFileData, getObject, getOpenSearchData, getQueueUrl, insertWithId, listFileWithoutLimit, logger, signedUrl } from 'tango-app-api-middleware';
2
2
  import { findOneUserAudit } from '../service/userAudit.service.js';
3
3
  import { aggregateStoreAudit, findOneStoreAudit } from '../service/storeAudit.service.js';
4
4
  import AdmZip from 'adm-zip';
@@ -457,3 +457,37 @@ export async function openSearchLog( inputData, user, id ) {
457
457
  }
458
458
  }
459
459
 
460
+ export async function isFeatureRunning( req, res, next ) {
461
+ try {
462
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
463
+ const inputData = req.body;
464
+ logger.info( { index: openSearch.tangoEyeLargeLogs } );
465
+ const getQuery = {
466
+ size: 1,
467
+ query: {
468
+ bool: {
469
+ must: [
470
+ { term: { 'store_id.keyword': inputData.storeId } },
471
+ { term: { 'store_date.keyword': inputData.fileDate } },
472
+ { term: { 'module.keyword': inputData.moduleType ==='track'? 'live_features_retrigger':'features_retrigger' } },
473
+ { term: { 'zone_id.keyword': inputData.moduleType === 'zone'? inputData.zoneName :'traffic_zone' } },
474
+ { term: { 'completed_st': false } },
475
+ { term: { 'initiated_st': true } },
476
+ ],
477
+ },
478
+ },
479
+ };
480
+
481
+ const getId = await getOpenSearchData( openSearch.tangoEyeLargeLogs, getQuery );
482
+ if ( getId?.body?.hits?.hits?.length > 0 ) {
483
+ return res.sendError( `This store is already being processed for the selected date. Please try again later.`, 400 );
484
+ } else {
485
+ next();
486
+ }
487
+ } catch ( error ) {
488
+ const err = error.message || 'Internal Server Error';
489
+ logger.error( { error: error, message: req.query, function: 'isFeatureRunning' } );
490
+ return res.sendError( err, 500 );
491
+ }
492
+ }
493
+