tango-app-api-analysis-traffic 3.0.0-alpha.2 → 3.0.0-alpha.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
|
@@ -407,13 +407,15 @@ export const headerLocationsV1 = async ( req, res ) => {
|
|
|
407
407
|
try {
|
|
408
408
|
let reqestData = req.body;
|
|
409
409
|
let getUserEmail = req.user.email;
|
|
410
|
+
let getUserType = req.user.userType;
|
|
410
411
|
let getClientId = reqestData.clientId;
|
|
411
|
-
let totalStores = await getAllStores( getUserEmail, getClientId );
|
|
412
|
+
let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
|
|
412
413
|
if ( totalStores && totalStores.length>0 ) {
|
|
413
414
|
let storeQuery = [
|
|
414
415
|
{
|
|
415
416
|
$match: {
|
|
416
417
|
$and: [
|
|
418
|
+
{ clientId: { $eq: getClientId } },
|
|
417
419
|
{ storeId: { $in: totalStores } },
|
|
418
420
|
],
|
|
419
421
|
},
|
|
@@ -452,67 +454,63 @@ export const headerLocationsV1 = async ( req, res ) => {
|
|
|
452
454
|
|
|
453
455
|
export const headerGroupsV1 = async ( req, res ) => {
|
|
454
456
|
try {
|
|
455
|
-
|
|
457
|
+
let requestData = req.body;
|
|
456
458
|
let getUserEmail = req.user.email;
|
|
457
|
-
let
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
{
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
$unwind: {
|
|
494
|
-
path: '$groups', preserveNullAndEmptyArrays: true,
|
|
495
|
-
},
|
|
496
|
-
},
|
|
497
|
-
{
|
|
498
|
-
$unwind: {
|
|
499
|
-
path: '$groups.groupName', preserveNullAndEmptyArrays: true,
|
|
459
|
+
let getUserType = req.user.userType;
|
|
460
|
+
const assignedQuery = {
|
|
461
|
+
clientId: requestData.clientId,
|
|
462
|
+
userEmail: getUserEmail,
|
|
463
|
+
};
|
|
464
|
+
let groupIds;
|
|
465
|
+
const getAssignedType = await findOneUserAssignedStore( assignedQuery );
|
|
466
|
+
if ( getAssignedType ) {
|
|
467
|
+
if ( getAssignedType.userType == 'client' ) {
|
|
468
|
+
if ( getAssignedType.assignedType == 'allstores' ) {
|
|
469
|
+
groupIds = await getGroupIds( requestData.clientId );
|
|
470
|
+
} else if ( getAssignedType.assignedType == 'group' ) {
|
|
471
|
+
groupIds = await getAssignedGroupIds( requestData.clientId, getUserEmail );
|
|
472
|
+
}
|
|
473
|
+
} else if ( getAssignedType.userType == 'tango' ) {
|
|
474
|
+
groupIds = await getGroupIds( requestData.clientId );
|
|
475
|
+
} else {
|
|
476
|
+
groupIds = [];
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
if ( getUserType == 'tango' ) {
|
|
480
|
+
groupIds = await getGroupIds( requestData.clientId );
|
|
481
|
+
} else {
|
|
482
|
+
return res.sendError( 'No User Assign', 400 );
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if ( groupIds && groupIds.length > 0 ) {
|
|
487
|
+
let groupQuery = [
|
|
488
|
+
{
|
|
489
|
+
$match: {
|
|
490
|
+
$and: [
|
|
491
|
+
{ clientId: { $eq: requestData.clientId } },
|
|
492
|
+
{ _id: { $in: groupIds } },
|
|
493
|
+
],
|
|
494
|
+
},
|
|
500
495
|
},
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
496
|
+
{
|
|
497
|
+
$project: {
|
|
498
|
+
_id: 0,
|
|
499
|
+
groupName: 1,
|
|
500
|
+
},
|
|
506
501
|
},
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
502
|
+
];
|
|
503
|
+
const groupResult = await aggregateGroup( groupQuery );
|
|
504
|
+
if ( groupResult && groupResult.length > 0 ) {
|
|
505
|
+
return res.sendSuccess( { groupData: groupResult } );
|
|
506
|
+
} else {
|
|
507
|
+
return res.sendError( 'No Group', 400 );
|
|
508
|
+
}
|
|
512
509
|
} else {
|
|
513
510
|
return res.sendError( 'No Group', 400 );
|
|
514
511
|
}
|
|
515
512
|
} catch ( error ) {
|
|
513
|
+
console.log( 'error =>', error );
|
|
516
514
|
logger.error( { error: error, message: req.query, function: 'trafficCards' } );
|
|
517
515
|
return res.sendError( { error: error }, 500 );
|
|
518
516
|
}
|
|
@@ -522,8 +520,9 @@ export const headerStoresV1 = async ( req, res ) => {
|
|
|
522
520
|
try {
|
|
523
521
|
let reqestData = req.body;
|
|
524
522
|
let getUserEmail = req.user.email;
|
|
523
|
+
let getUserType = req.user.userType;
|
|
525
524
|
let getClientId = reqestData.clientId;
|
|
526
|
-
let totalStores = await getAllStores( getUserEmail, getClientId );
|
|
525
|
+
let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
|
|
527
526
|
if ( totalStores && totalStores.length>0 ) {
|
|
528
527
|
let storeQuery = [];
|
|
529
528
|
if ( reqestData.city.length>0 && reqestData.group.length>0 ) {
|
|
@@ -586,7 +585,7 @@ export const headerStoresV1 = async ( req, res ) => {
|
|
|
586
585
|
},
|
|
587
586
|
];
|
|
588
587
|
} else {
|
|
589
|
-
let totalStores = await getAllStores( getUserEmail, getClientId );
|
|
588
|
+
let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
|
|
590
589
|
storeQuery = [
|
|
591
590
|
{
|
|
592
591
|
$match: {
|
|
@@ -607,7 +606,7 @@ export const headerStoresV1 = async ( req, res ) => {
|
|
|
607
606
|
|
|
608
607
|
const storeList = await aggregateStore( storeQuery );
|
|
609
608
|
if ( storeList && storeList.length > 0 ) {
|
|
610
|
-
return res.sendSuccess( storeList );
|
|
609
|
+
return res.sendSuccess( { storesData: storeList } );
|
|
611
610
|
} else {
|
|
612
611
|
return res.sendError( 'No Stores', 400 );
|
|
613
612
|
}
|
|
@@ -621,7 +620,7 @@ export const headerStoresV1 = async ( req, res ) => {
|
|
|
621
620
|
}
|
|
622
621
|
};
|
|
623
622
|
|
|
624
|
-
async function getAllStores( getUserEmail, getClientId ) {
|
|
623
|
+
async function getAllStores( getUserEmail, getClientId, getUserType ) {
|
|
625
624
|
try {
|
|
626
625
|
if ( getUserEmail && getUserEmail !='' ) {
|
|
627
626
|
const assignedQuery = {
|
|
@@ -660,21 +659,26 @@ async function getAllStores( getUserEmail, getClientId ) {
|
|
|
660
659
|
return false;
|
|
661
660
|
}
|
|
662
661
|
} else if ( getAssignedType.userType == 'tango' ) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
overAllStores = getAllS;
|
|
668
|
-
}
|
|
669
|
-
return overAllStores;
|
|
670
|
-
} else {
|
|
671
|
-
return false;
|
|
662
|
+
let overAllStores = [];
|
|
663
|
+
let getAllS = await getAssignedAllStores( getClientId );
|
|
664
|
+
if ( getAllS && getAllS.length >0 ) {
|
|
665
|
+
overAllStores = getAllS;
|
|
672
666
|
}
|
|
667
|
+
return overAllStores;
|
|
673
668
|
} else {
|
|
674
669
|
return false;
|
|
675
670
|
}
|
|
676
671
|
} else {
|
|
677
|
-
|
|
672
|
+
if ( getUserType && getUserType == 'tango' ) {
|
|
673
|
+
let overAllStores = [];
|
|
674
|
+
let getAllS = await getAssignedAllStores( getClientId );
|
|
675
|
+
if ( getAllS && getAllS.length >0 ) {
|
|
676
|
+
overAllStores = getAllS;
|
|
677
|
+
}
|
|
678
|
+
return overAllStores;
|
|
679
|
+
} else {
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
678
682
|
}
|
|
679
683
|
} else {
|
|
680
684
|
return false;
|
|
@@ -903,3 +907,77 @@ async function getLocationStores( userClientId, cityList ) {
|
|
|
903
907
|
logger.error( { error: error, message: data, function: 'getLocationStores' } );
|
|
904
908
|
}
|
|
905
909
|
}
|
|
910
|
+
|
|
911
|
+
async function getGroupIds( userClientId ) {
|
|
912
|
+
try {
|
|
913
|
+
if ( userClientId && userClientId !='' ) {
|
|
914
|
+
let groupQuery = [
|
|
915
|
+
{
|
|
916
|
+
$match: {
|
|
917
|
+
$and: [
|
|
918
|
+
{ clientId: { $eq: userClientId } },
|
|
919
|
+
],
|
|
920
|
+
},
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
$group: {
|
|
924
|
+
_id: null,
|
|
925
|
+
groupName: { $push: '$_id' },
|
|
926
|
+
},
|
|
927
|
+
},
|
|
928
|
+
];
|
|
929
|
+
const groupGroupIds = await aggregateGroup( groupQuery );
|
|
930
|
+
if ( groupGroupIds && groupGroupIds.length>0 && groupGroupIds[0]?.groupName.length > 0 ) {
|
|
931
|
+
let uniqueGroupIds = [ ...new Set( groupGroupIds[0].groupName ) ];
|
|
932
|
+
return uniqueGroupIds;
|
|
933
|
+
} else {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
} else {
|
|
937
|
+
return false;
|
|
938
|
+
}
|
|
939
|
+
} catch ( error ) {
|
|
940
|
+
console.log( 'getGroupIds error =>', error );
|
|
941
|
+
logger.error( { error: error, message: data, function: 'getGroupIds' } );
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
async function getAssignedGroupIds( userClientId, getUserEmail ) {
|
|
946
|
+
try {
|
|
947
|
+
if ( userClientId && userClientId !='' && getUserEmail && getUserEmail !='' ) {
|
|
948
|
+
let groupQuery = [
|
|
949
|
+
{
|
|
950
|
+
$match: {
|
|
951
|
+
$and: [
|
|
952
|
+
{ clientId: { $eq: userClientId } },
|
|
953
|
+
{ userEmail: { $eq: getUserEmail } },
|
|
954
|
+
{ assignedType: { $eq: 'group' } },
|
|
955
|
+
],
|
|
956
|
+
},
|
|
957
|
+
},
|
|
958
|
+
{
|
|
959
|
+
$group: {
|
|
960
|
+
_id: null,
|
|
961
|
+
groupName: { $push: '$assignedValue' },
|
|
962
|
+
},
|
|
963
|
+
},
|
|
964
|
+
];
|
|
965
|
+
const groupStoreList = await aggregateUserAssignedStore( groupQuery );
|
|
966
|
+
if ( groupStoreList && groupStoreList.length>0 && groupStoreList[0]?.groupName.length > 0 ) {
|
|
967
|
+
let uniqueGroupIdsData = [ ...new Set( groupStoreList[0].groupName ) ];
|
|
968
|
+
let uniqueGroupIds = [];
|
|
969
|
+
for ( let i = 0; i < uniqueGroupIdsData.length; i++ ) {
|
|
970
|
+
uniqueGroupIds.push( new ObjectId( uniqueGroupIdsData[i] ) );
|
|
971
|
+
}
|
|
972
|
+
return uniqueGroupIds;
|
|
973
|
+
} else {
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
976
|
+
} else {
|
|
977
|
+
return false;
|
|
978
|
+
}
|
|
979
|
+
} catch ( error ) {
|
|
980
|
+
console.log( 'getAssignedGroupIds error =>', error );
|
|
981
|
+
logger.error( { error: error, message: data, function: 'getAssignedGroupIds' } );
|
|
982
|
+
}
|
|
983
|
+
}
|