tango-app-api-trax 3.9.64 → 3.9.66
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
|
@@ -455,7 +455,7 @@ export const flagCardsV1 = async ( req, res ) => {
|
|
|
455
455
|
{
|
|
456
456
|
client_id: clientId,
|
|
457
457
|
publish: true,
|
|
458
|
-
checkListType: { $
|
|
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: { $
|
|
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
|
-
|
|
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: { $
|
|
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
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
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?.
|
|
2309
|
+
if ( !getChecklistPerformanceData?.length ) {
|
|
2317
2310
|
return res.sendError( 'No data found', 204 );
|
|
2318
2311
|
}
|
|
2319
2312
|
|
|
2320
|
-
let getTotalCount = getChecklistPerformanceData
|
|
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,38 @@ 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
|
+
// The UI sends some columns as display labels (e.g. 'Compliance') rather than the
|
|
2368
|
+
// data field name, so map those to the real keys; raw field names pass through.
|
|
2369
|
+
const SORT_FIELD_MAP = {
|
|
2370
|
+
'Compliance': 'complianceRate',
|
|
2371
|
+
'Checklist Name': 'checkListName',
|
|
2372
|
+
'Coverage': 'coverage',
|
|
2373
|
+
'Assigned Stores': 'assignedStores',
|
|
2374
|
+
'Flagged Stores': 'flaggedStores',
|
|
2375
|
+
'Question Flags': 'customQuestionFlagCount',
|
|
2376
|
+
'Not Submitted Flags': 'customTimeFlagCount',
|
|
2377
|
+
'Detection Flags': 'flagCount',
|
|
2378
|
+
'Flags': 'flagCount',
|
|
2379
|
+
};
|
|
2380
|
+
const sortColumnName = SORT_FIELD_MAP[requestData.sortColumnName] || requestData.sortColumnName;
|
|
2381
|
+
if ( sortColumnName && sortColumnName != '' && requestData.sortBy && requestData.sortBy != '' ) {
|
|
2382
|
+
const sortDir = parseInt( requestData.sortBy, 10 ) === -1 ? -1 : 1;
|
|
2383
|
+
getChecklistPerformanceData.sort( ( a, b ) => {
|
|
2384
|
+
const av = a?.[sortColumnName];
|
|
2385
|
+
const bv = b?.[sortColumnName];
|
|
2386
|
+
const an = typeof av === 'number' ? av : parseFloat( av );
|
|
2387
|
+
const bn = typeof bv === 'number' ? bv : parseFloat( bv );
|
|
2388
|
+
if ( !Number.isNaN( an ) && !Number.isNaN( bn ) ) return ( an - bn ) * sortDir;
|
|
2389
|
+
return String( av ?? '' ).localeCompare( String( bv ?? '' ) ) * sortDir;
|
|
2390
|
+
} );
|
|
2391
|
+
} else {
|
|
2392
|
+
getChecklistPerformanceData.sort( ( a, b ) => ( b?.submittedChecklist || 0 ) - ( a?.submittedChecklist || 0 ) );
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2371
2395
|
if ( requestData.export ) {
|
|
2372
2396
|
const exportdata = [];
|
|
2373
2397
|
getChecklistPerformanceData.forEach( ( element ) => {
|
|
@@ -2426,7 +2450,8 @@ export const flagTablesV2 = async ( req, res ) => {
|
|
|
2426
2450
|
}
|
|
2427
2451
|
|
|
2428
2452
|
result.totalCount = getTotalCount;
|
|
2429
|
-
|
|
2453
|
+
// Paginate in JS now that the full set is sorted by the merged values.
|
|
2454
|
+
result.checklistPerformance = getChecklistPerformanceData.slice( skip, skip + limit );
|
|
2430
2455
|
return res.sendSuccess( result );
|
|
2431
2456
|
} catch ( error ) {
|
|
2432
2457
|
console.log( 'error =>', error );
|