tango-app-api-trax 3.9.63 → 3.9.65

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-trax",
3
- "version": "3.9.63",
3
+ "version": "3.9.65",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -128,7 +128,7 @@ export async function getcustomerunattendedlist( req, res ) {
128
128
  req.body.liveDate = new Set();
129
129
  req.body.eodDate = new Set();
130
130
  config.forEach( ( data ) => {
131
- if ( data?.aiConfig?.advancedConfig?.dataProcessing == 'live' ) {
131
+ if ( data?.aiConfig?.advancedConfig?.dataProcessing.includes( 'live' ) ) {
132
132
  req.body.liveDate.add( data.date_string );
133
133
  } else {
134
134
  req.body.eodDate.add( data.date_string );
@@ -455,7 +455,7 @@ export const flagCardsV1 = async ( req, res ) => {
455
455
  {
456
456
  client_id: clientId,
457
457
  publish: true,
458
- checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum', 'outsidebusinesshoursqueuetracking', 'halfshutter', 'tvcompliance', 'cameratampering', 'queuealert', 'staffgrouping', 'boxalert', 'employeeCount', 'storehygienemonitoring', 'unattendeddetection' ] },
458
+ checkListType: { $ne: 'custom' },
459
459
  },
460
460
  { checkListType: 1 },
461
461
  ),
@@ -472,7 +472,6 @@ export const flagCardsV1 = async ( req, res ) => {
472
472
  flagCards.totalFlag = flagCards.questionFlag.count + flagCards.delayInSubmission.count;
473
473
 
474
474
  const published = publishedAiChecklists.map( ( val ) => val?.checkListType );
475
-
476
475
  if ( resultData && resultData.status_code === '200' ) {
477
476
  published.forEach( ( item ) => {
478
477
  if ( resultData[item] ) {
@@ -591,7 +590,7 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
591
590
  {
592
591
  client_id: requestData.clientId,
593
592
  publish: true,
594
- checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum', 'employeeCount', 'employeemonitoring', 'activitymonitoring' ] },
593
+ checkListType: { $ne: 'custom' },
595
594
  },
596
595
  { checkListType: 1 },
597
596
  );
@@ -660,7 +659,10 @@ export const flagTablesV1 = async ( req, res ) => {
660
659
  );
661
660
 
662
661
  if ( requestData?.filter === 'all' ) {
663
- findAndQuery.push( { $or: [ { checkListType: { $in: [ 'custom', 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum', 'employeeCount', 'employeemonitoring', 'activitymonitoring' ] } } ] } );
662
+ // 'all' = every checklist type (custom + all detection types); $eq|$ne 'custom'
663
+ // spans both. Needs the '$' prefix — 'eq'/'ne' without it matches literally
664
+ // nothing, which is why the 'all' filter returned no rows.
665
+ findAndQuery.push( { $or: [ { checkListType: { $eq: 'custom' } }, { checkListType: { $ne: 'custom' } } ] } );
664
666
  } else if ( requestData?.filter === 'question' ) {
665
667
  findAndQuery.push( { checkListType: 'custom' } );
666
668
  findAndQuery.push( { questionFlag: { $gte: 1 } } );
@@ -668,7 +670,7 @@ export const flagTablesV1 = async ( req, res ) => {
668
670
  findAndQuery.push( { checkListType: 'custom' } );
669
671
  findAndQuery.push( { timeFlag: { $gte: 1 } } );
670
672
  } else if ( requestData?.filter === 'detection' ) {
671
- findAndQuery.push( { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection', 'cleaning', 'scrum', 'employeeCount', 'employeemonitoring', 'activitymonitoring' ] } } );
673
+ findAndQuery.push( { checkListType: { $ne: 'custom' } } );
672
674
  } else if ( requestData?.filter === 'runAI' ) {
673
675
  findAndQuery.push( { runAIQuestionCount: { $gte: 1 } } );
674
676
  }
@@ -2232,6 +2234,7 @@ export const flagTablesV2 = async ( req, res ) => {
2232
2234
  correctAnswers: { $subtract: [ '$submittedQuestionCount', '$questionFlag' ] },
2233
2235
  customQuestionFlagCount: '$questionFlag',
2234
2236
  customTimeFlagCount: '$timeFlag',
2237
+ submittedChecklist: 1,
2235
2238
  aiStoreList: 1,
2236
2239
  runAIQuestionCount: 1,
2237
2240
  },
@@ -2266,6 +2269,7 @@ export const flagTablesV2 = async ( req, res ) => {
2266
2269
  },
2267
2270
  customQuestionFlagCount: 1,
2268
2271
  customTimeFlagCount: 1,
2272
+ submittedChecklist: 1,
2269
2273
  aiStoreList: 1,
2270
2274
  runAIQuestionCount: 1,
2271
2275
  },
@@ -2276,23 +2280,12 @@ export const flagTablesV2 = async ( req, res ) => {
2276
2280
  // return res.sendError( { error: 'No Data Found' }, 204 );
2277
2281
  // }
2278
2282
 
2279
- if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
2280
- findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
2281
- } else {
2282
- findQuery.push( { $sort: { ['submittedChecklist']: -1 } } );
2283
- }
2284
-
2285
- findQuery.push( {
2286
- $facet: {
2287
- total: [
2288
- { $count: 'count' },
2289
- ],
2290
-
2291
- data: [
2292
- { $skip: skip }, { $limit: limit },
2293
- ],
2294
- },
2295
- } );
2283
+ // Detection / runAI / all flag values (flaggedStores, flagCount,
2284
+ // complianceRate, assignedStores) are merged from the Lambda AFTER this
2285
+ // aggregation, so sorting and pagination are done in JS post-merge (below).
2286
+ // Sorting here would order rows by stale pre-Lambda values the bug this
2287
+ // fixes. One row per checklist keeps the in-memory set small.
2288
+ findQuery.push( { $sort: { ['submittedChecklist']: -1 } } );
2296
2289
 
2297
2290
  // The detection Lambda only needs request params (not the aggregation result),
2298
2291
  // so fire it concurrently with the Mongo aggregation instead of after it.
@@ -2313,12 +2306,11 @@ export const flagTablesV2 = async ( req, res ) => {
2313
2306
  mayNeedLambda ? LamdaServiceCall( LamdaURL, detectionPayload ) : Promise.resolve( null ),
2314
2307
  ] );
2315
2308
 
2316
- if ( !getChecklistPerformanceData?.[0]?.total?.[0]?.count ) {
2309
+ if ( !getChecklistPerformanceData?.length ) {
2317
2310
  return res.sendError( 'No data found', 204 );
2318
2311
  }
2319
2312
 
2320
- let getTotalCount = getChecklistPerformanceData?.[0]?.total?.[0]?.count;
2321
- getChecklistPerformanceData = getChecklistPerformanceData?.[0]?.data;
2313
+ let getTotalCount = getChecklistPerformanceData.length;
2322
2314
  if ( getChecklistPerformanceData.length ) {
2323
2315
  const detectionChecklists = getChecklistPerformanceData?.filter( ( val ) => val?.checkListType !== 'custom' );
2324
2316
 
@@ -2368,6 +2360,25 @@ export const flagTablesV2 = async ( req, res ) => {
2368
2360
  }
2369
2361
  }
2370
2362
 
2363
+ // Sort in JS AFTER the Lambda merge so detection / runAI / all rows order by
2364
+ // their real (merged) flaggedStores / flagCount / complianceRate / assignedStores
2365
+ // instead of the stale pre-merge values. Numeric columns (incl. complianceRate,
2366
+ // which is a fixed-point string) compare numerically; text columns fall back to locale.
2367
+ const sortColumnName = requestData.sortColumnName;
2368
+ if ( sortColumnName && sortColumnName != '' && requestData.sortBy && requestData.sortBy != '' ) {
2369
+ const sortDir = parseInt( requestData.sortBy, 10 ) === -1 ? -1 : 1;
2370
+ getChecklistPerformanceData.sort( ( a, b ) => {
2371
+ const av = a?.[sortColumnName];
2372
+ const bv = b?.[sortColumnName];
2373
+ const an = typeof av === 'number' ? av : parseFloat( av );
2374
+ const bn = typeof bv === 'number' ? bv : parseFloat( bv );
2375
+ if ( !Number.isNaN( an ) && !Number.isNaN( bn ) ) return ( an - bn ) * sortDir;
2376
+ return String( av ?? '' ).localeCompare( String( bv ?? '' ) ) * sortDir;
2377
+ } );
2378
+ } else {
2379
+ getChecklistPerformanceData.sort( ( a, b ) => ( b?.submittedChecklist || 0 ) - ( a?.submittedChecklist || 0 ) );
2380
+ }
2381
+
2371
2382
  if ( requestData.export ) {
2372
2383
  const exportdata = [];
2373
2384
  getChecklistPerformanceData.forEach( ( element ) => {
@@ -2426,7 +2437,8 @@ export const flagTablesV2 = async ( req, res ) => {
2426
2437
  }
2427
2438
 
2428
2439
  result.totalCount = getTotalCount;
2429
- result.checklistPerformance = getChecklistPerformanceData;
2440
+ // Paginate in JS now that the full set is sorted by the merged values.
2441
+ result.checklistPerformance = getChecklistPerformanceData.slice( skip, skip + limit );
2430
2442
  return res.sendSuccess( result );
2431
2443
  } catch ( error ) {
2432
2444
  console.log( 'error =>', error );