tango-app-api-analysis-traffic 3.8.7-vms.3 → 3.8.7-vms.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-analysis-traffic",
3
- "version": "3.8.7-vms.3",
3
+ "version": "3.8.7-vms.4",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -406,40 +406,112 @@ export async function footFallImages( req, res ) {
406
406
  ],
407
407
  },
408
408
  },
409
- // '_source': [ 'dateString', 'storeId', 'duplicateCount', 'footfallCount', 'employeeCount', 'houseKeepingCount', 'junkCount', 'status', 'ticketId', 'comments', 'userName', 'role', 'createdAt', 'email', 'houseKeepingACCount', 'duplicateACCount', 'employeeACCount', 'junkACCount', 'approverEmail', 'approverRole', 'approverUserName' ],
409
+ '_source': [ 'dateString', 'storeId', 'mappingInfo', 'revicedFootfall', 'revicedPerc', 'createdAt', 'updatedAt', 'footfallCount' ],
410
410
 
411
411
  };
412
412
 
413
413
  const getData = await getOpenSearchData( opensearch.footfallDirectory, query );
414
414
  const ticketDetails = getData?.body?.hits?.hits[0];
415
415
  let temp = [];
416
- ticketDetails?._source? temp.push( ticketDetails?._source ) :null;
417
- // temp[0].status = 'open';
418
- if ( ticketDetails?._source?.status == 'closed' ) {
419
- delete temp[0].status;
420
- temp.push( { ...ticketDetails?._source, status: 'closed' } );
421
-
422
- temp[1].userName = getData?.body?.hits?.hits?.[0]?._source?.approverUserName;
423
- temp[1].email = getData?.body?.hits?.hits?.[0]?._source?.approverEmail;
424
- temp[1].role = getData?.body?.hits?.hits?.[0]?._source?.approverRole;
425
- temp[1].employeeCount = getData?.body?.hits?.hits?.[0]?._source?.employeeACCount;
426
- temp[1].houseKeepingCount = getData?.body?.hits?.hits?.[0]?._source?.houseKeepingACCount;
427
- temp[1].duplicateCount = getData?.body?.hits?.hits?.[0]?._source?.duplicateACCount;
428
- temp[1].junkCount = getData?.body?.hits?.hits?.[0]?._source?.junkACCount;
429
- }
430
- const LamdaURL = revop.getImages;
431
- let resultData = await LamdaServiceCall( LamdaURL, inputData );
432
- logger.info( { resultData: resultData } );
433
- if ( resultData ) {
434
- temp.length? temp[0].status = 'open': null;
435
- if ( resultData.status_code == '200' ) {
436
- return res.sendSuccess( { ...resultData, ticketStatus: temp?.length > 0? temp : null, config: req?.store?.footfallDirectoryConfigs } );
437
- } else {
438
- return res.sendError( 'No Content', 204 );
439
- }
440
- } else {
441
- return res.sendError( 'No Content', 204 );
442
- }
416
+ const footfallValue = ticketDetails?._source?.footfallCount ?? 0;
417
+ const mappingInfoArray = ticketDetails?._source?.mappingInfo ?? [];
418
+
419
+ // Helper to get mappingInfo for an actionType
420
+ function getMappingForType( type ) {
421
+ return mappingInfoArray.find( ( m ) => m.type === type ) || {};
422
+ }
423
+
424
+ // List of actionTypes to process in sequence
425
+
426
+ if ( req.user.userType !== 'tango' && req.user.role !== 'superadmin' ) {
427
+ switch ( req.user.role ) {
428
+ case 'user':
429
+ const actionTypesUser = [ 'tagging', 'finalreview' ];
430
+ temp = actionTypesUser.map( ( type ) => {
431
+ const mapping = getMappingForType( type );
432
+
433
+ const revisedFootfall = mapping.revisedFootfall ?? 0;
434
+ // Do not divide by 0
435
+ const revisedPerc =
436
+ footfallValue > 0 ?
437
+ `${Math.round( ( revisedFootfall / footfallValue ) * 100 )}` :
438
+ '0';
439
+
440
+ // Since keys in count can be dynamic, just deep copy the count object or empty object
441
+ const countObj = mapping.count ? { ...mapping.count } : {};
442
+
443
+ return {
444
+ actionType: type,
445
+ footfall: footfallValue,
446
+ revicedFootfall: revisedFootfall,
447
+ revicedPerc: revisedPerc,
448
+ count: countObj,
449
+ };
450
+ } );
451
+ break;
452
+ case 'admin':
453
+ const actionTypesAdmin = [ 'tagging', 'review', 'finalreview' ];
454
+ temp = actionTypesAdmin.map( ( type ) => {
455
+ const mapping = getMappingForType( type );
456
+
457
+ const revisedFootfall = mapping.revisedFootfall ?? 0;
458
+ // Do not divide by 0
459
+ const revisedPerc =
460
+ footfallValue > 0 ?
461
+ `${Math.round( ( revisedFootfall / footfallValue ) * 100 )}` :
462
+ '0';
463
+
464
+ // Since keys in count can be dynamic, just deep copy the count object or empty object
465
+ const countObj = mapping.count ? { ...mapping.count } : {};
466
+
467
+ return {
468
+ actionType: type,
469
+ footfall: footfallValue,
470
+ revicedFootfall: revisedFootfall,
471
+ revicedPerc: revisedPerc,
472
+ count: countObj,
473
+ };
474
+ } );
475
+ break;
476
+ }
477
+ } else {
478
+ const actionTypes = [ 'tagging', 'review', 'approve', 'finalreview' ];
479
+ temp = actionTypes.map( ( type ) => {
480
+ const mapping = getMappingForType( type );
481
+
482
+ const revisedFootfall = mapping.revisedFootfall ?? 0;
483
+ // Do not divide by 0
484
+ const revisedPerc =
485
+ footfallValue > 0 ?
486
+ `${Math.round( ( revisedFootfall / footfallValue ) * 100 )}` :
487
+ '0';
488
+
489
+ // Since keys in count can be dynamic, just deep copy the count object or empty object
490
+ const countObj = mapping.count ? { ...mapping.count } : {};
491
+
492
+ return {
493
+ actionType: type,
494
+ footfall: footfallValue,
495
+ revicedFootfall: revisedFootfall,
496
+ revicedPerc: revisedPerc,
497
+ count: countObj,
498
+ };
499
+ } );
500
+ }
501
+
502
+
503
+ const LamdaURL = revop.getImages;
504
+ let resultData = await LamdaServiceCall( LamdaURL, inputData );
505
+ if ( resultData ) {
506
+ // temp.length? temp[0].status = 'open': null;
507
+ if ( resultData.status_code == '200' ) {
508
+ return res.sendSuccess( { ...resultData, ticketStatus: temp?.length > 0? temp : null, config: req?.store?.footfallDirectoryConfigs } );
509
+ } else {
510
+ return res.sendError( 'No Content', 204 );
511
+ }
512
+ } else {
513
+ return res.sendError( 'No Content', 204 );
514
+ }
443
515
  } catch ( error ) {
444
516
  logger.error( { message: error, data: req.query, function: 'storeProcessedData' } );
445
517
  const err = error.message || 'Internal Server Error';