tango-app-api-audit 3.6.8 → 3.6.10

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.6.8",
3
+ "version": "3.6.10",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2131,7 +2131,7 @@ export async function save( req, res ) {
2131
2131
  retry: 1,
2132
2132
  } ),
2133
2133
  MessageGroupId: 'my-group-1', // Required for FIFO queues
2134
- MessageDeduplicationId: Date.now().toString(), // Or a UUID, if content-based deduplication is off
2134
+ MessageDeduplicationId: `${inputData.storeId}_${inputData.fileDate}_${inputData.auditType}_${Date.now().toString()}`, // Or a UUID, if content-based deduplication is off
2135
2135
  }:
2136
2136
  {
2137
2137
  QueueUrl: ( auditConfig?.isCheckMinAfterCount ==1 && inputData.customerCount > auditConfig?.minAfterCount ) ? `${sqs.url}${sqs.feature_new}`: `${sqs.url}${sqs.feature}`,
@@ -2143,46 +2143,54 @@ export async function save( req, res ) {
2143
2143
  process_type: 'audit',
2144
2144
  } ),
2145
2145
  };
2146
- const sqsProduceQueueCopy = {
2147
- QueueUrl: `${sqs.url}track-output-copy.fifo`,
2148
- MessageBody: JSON.stringify( {
2149
- store_id: inputData.storeId,
2150
- zone_id: [ 'traffic_zone' ],
2151
- streams: streams || [],
2152
- store_date: inputData.fileDate,
2153
- bucket_name: 'tango-yolo-v2-output',
2154
- time: '23:00',
2155
- retry: 1,
2156
- } ),
2157
- MessageGroupId: 'my-group-1', // Required for FIFO queues
2158
- MessageDeduplicationId: Date.now().toString(), // Or a UUID, if content-based deduplication is off
2159
- };
2160
2146
 
2161
- let sqsQueue;
2162
- let sqsQueueCopy;
2147
+
2163
2148
  if ( inputData.moduleType === 'track' ) {
2164
- const [ firstResponse, secondResponse ] = await Promise.all( [
2165
- sendMessageToFIFOQueue( sqsProduceQueue ),
2166
- sendMessageToFIFOQueue( sqsProduceQueueCopy ),
2167
- ] );
2149
+ const firstResponse = await sendMessageToFIFOQueue( sqsProduceQueue );
2168
2150
 
2169
- sqsQueue = firstResponse;
2170
- sqsQueueCopy = secondResponse;
2151
+ /* openSearch logs start */
2152
+ id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.email}_${Date.now()}`;
2153
+ const message = {
2154
+ getBody: getBody,
2155
+ streams: streams,
2156
+ sqsProduceQueue: sqsProduceQueue,
2157
+ sqsQueue: firstResponse,
2158
+ };
2159
+ temp.message =JSON.stringify( message );
2160
+ await openSearchLog( temp, req.user, id );
2161
+ /* openSearch logs end */
2162
+
2163
+ if ( firstResponse.statusCode ) {
2164
+ const results = await Promise.allSettled( [
2165
+ withRetry( () => sendMessageToFIFOQueue( sqsProduceQueue ), 3, 2000 ),
2166
+ ] );
2167
+ const [ firstRetryResponse ] = results;
2168
+ /* openSearch logs start */
2169
+ id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.email}_${Date.now()}`;
2170
+ const message = {
2171
+ getBody: getBody,
2172
+ streams: streams,
2173
+ sqsProduceQueue: sqsProduceQueue,
2174
+ sqsQueue: firstRetryResponse,
2175
+ };
2176
+ temp.message =JSON.stringify( message );
2177
+ await openSearchLog( temp, req.user, id );
2178
+ /* openSearch logs end */
2179
+ }
2171
2180
  } else {
2172
- sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
2173
- }
2174
- /* openSearch logs start */
2175
- id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.email}_${Date.now()}`;
2176
- const message = {
2177
- getBody: getBody,
2178
- streams: streams,
2179
- sqsProduceQueue: sqsProduceQueue,
2180
- sqsQueue: sqsQueue,
2181
- sqsQueueCopy: sqsQueueCopy,
2182
- };
2183
- temp.message =JSON.stringify( message );
2184
- await openSearchLog( temp, req.user, id );
2181
+ const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
2182
+ /* openSearch logs start */
2183
+ id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.email}_${Date.now()}`;
2184
+ const message = {
2185
+ getBody: getBody,
2186
+ streams: streams,
2187
+ sqsProduceQueue: sqsProduceQueue,
2188
+ sqsQueue: sqsQueue,
2189
+ };
2190
+ temp.message =JSON.stringify( message );
2191
+ await openSearchLog( temp, req.user, id );
2185
2192
  /* openSearch logs end */
2193
+ }
2186
2194
  if ( inputData.moduleType === 'track' ) {
2187
2195
  // declare id
2188
2196
  id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.email}_${Date.now()}`;
@@ -2210,6 +2218,25 @@ export async function save( req, res ) {
2210
2218
  }
2211
2219
  }
2212
2220
 
2221
+ // Retry send SQS message
2222
+ async function withRetry( fn, retries = 3, delay = 1000 ) {
2223
+ let lastError;
2224
+ for ( let attempt = 1; attempt <= retries; attempt++ ) {
2225
+ try {
2226
+ const result = await fn();
2227
+ return result; // success — return immediately
2228
+ } catch ( err ) {
2229
+ lastError = err;
2230
+ logger.error( `Attempt ${attempt} failed: ${err.message}` );
2231
+ if ( attempt < retries ) {
2232
+ await new Promise( ( res ) => setTimeout( res, delay ) ); // wait before retry
2233
+ }
2234
+ }
2235
+ }
2236
+ throw lastError; // all attempts failed
2237
+ }
2238
+
2239
+
2213
2240
  const filteredMap = async ( data ) => {
2214
2241
  const temp = data.map( ( item ) => item.img_name );
2215
2242
  return temp;
@@ -1244,13 +1244,13 @@ export async function summaryList( req, res ) {
1244
1244
 
1245
1245
  } );
1246
1246
  }
1247
- if ( inputData.complianceScore && inputData.complianceScore!= null ) {
1248
- logger.info( { complsc: inputData.complianceScore } );
1247
+ if ( inputData.complianceScore && inputData.complianceScore?.length > null ) {
1248
+ const values = Array.isArray( inputData.complianceScore ) ?
1249
+ inputData.complianceScore.map( Number ) :
1250
+ [ Number( inputData.complianceScore ) ];
1249
1251
  filter.push( {
1250
- range: {
1251
- 'ComplianceScore': {
1252
- lt: inputData.complianceScore,
1253
- },
1252
+ 'terms': {
1253
+ 'ComplianceScore': values,
1254
1254
  },
1255
1255
 
1256
1256
  } );
@@ -2083,13 +2083,11 @@ export async function summaryCard( req, res ) {
2083
2083
  } );
2084
2084
  }
2085
2085
 
2086
- if ( inputData?.complianceScore && inputData?.complianceScore !== null ) {
2086
+ if ( inputData?.complianceScore && inputData?.complianceScore?.length > 0 ) {
2087
2087
  filter.push(
2088
2088
  {
2089
- range: {
2090
- ComplianceScore: {
2091
- lt: inputData?.complianceScore, // 🔹 adjust threshold here (e.g. gte: 50 for >= 50%)
2092
- },
2089
+ 'terms': {
2090
+ 'ComplianceScore': inputData.complianceScore,
2093
2091
  },
2094
2092
  },
2095
2093
  );
@@ -155,7 +155,7 @@ export const summaryListSchema = joi.object( {
155
155
  joi.string().optional(),
156
156
  ).optional(),
157
157
  storeId: joi.array().items( joi.string().required() ).required(),
158
- complianceScore: joi.number().optional().allow( null ),
158
+ complianceScore: joi.array().items( joi.number().required() ).optional(),
159
159
  nearAddition: joi.string().optional().allow( '' ),
160
160
  isExport: joi.boolean().optional(),
161
161
  searchValue: joi.string().optional().allow( '' ),
@@ -226,7 +226,7 @@ export const summaryCardSchema = joi.object( {
226
226
  joi.string().optional(),
227
227
  ).optional(),
228
228
  storeId: joi.array().items( joi.string().required() ).required(),
229
- complianceScore: joi.number().optional().allow( null ),
229
+ complianceScore: joi.array().items( joi.number().required() ).optional(),
230
230
  nearAddition: joi.string().optional().allow( '' ),
231
231
  category: joi.string().optional() .valid( 'fake', 'genuine' ),
232
232
  } );
@@ -22,7 +22,7 @@ eyeTestAuditRouter.post( '/summary-card', isAllowedSessionHandler, accessVerific
22
22
  eyeTestAuditRouter.post( '/email-alert-log', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), isSuperAdmin, validate( emailAlertLogValid ), emailAlertLog );
23
23
 
24
24
  eyeTestAuditRouter.post( '/cluster-list', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( clusterListValid ), clusterList );
25
- eyeTestAuditRouter.get( '/rm-list', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), validate( rmListValid ), rmList );
25
+ eyeTestAuditRouter.get( '/rm-list', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ] } ), isSuperAdmin, validate( rmListValid ), rmList );
26
26
 
27
27
 
28
28
  // setting