tango-app-api-analysis-traffic 3.0.0-alpha.5 → 3.0.0-alpha.6

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.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.6",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -428,8 +428,9 @@ export const headerLocationsV1 = async ( req, res ) => {
428
428
  let reqestData = req.body;
429
429
  let getUserEmail = req.user.email;
430
430
  let getUserType = req.user.userType;
431
+ let getRole = req.user.role;
431
432
  let getClientId = reqestData.clientId;
432
- let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
433
+ let totalStores = await getAllStores( getUserEmail, getClientId, getUserType, getRole );
433
434
  if ( totalStores && totalStores.length>0 ) {
434
435
  let storeQuery = [
435
436
  {
@@ -477,30 +478,33 @@ export const headerGroupsV1 = async ( req, res ) => {
477
478
  let requestData = req.body;
478
479
  let getUserEmail = req.user.email;
479
480
  let getUserType = req.user.userType;
480
- const assignedQuery = {
481
- clientId: requestData.clientId,
482
- userEmail: getUserEmail,
483
- };
481
+ let getRole = req.user.role;
484
482
  let groupIds;
485
- const getAssignedType = await findOneUserAssignedStore( assignedQuery );
486
- if ( getAssignedType ) {
487
- if ( getAssignedType.userType == 'client' ) {
488
- if ( getAssignedType.assignedType == 'allstores' ) {
489
- groupIds = await getGroupIds( requestData.clientId );
490
- } else if ( getAssignedType.assignedType == 'group' ) {
491
- groupIds = await getAssignedGroupIds( requestData.clientId, getUserEmail );
492
- }
493
- } else if ( getAssignedType.userType == 'tango' ) {
483
+ if ( getUserType == 'tango' ) {
484
+ groupIds = await getGroupIds( requestData.clientId );
485
+ } else if ( getUserType == 'client' ) {
486
+ if ( getRole == 'superadmin' ) {
494
487
  groupIds = await getGroupIds( requestData.clientId );
495
488
  } else {
496
- groupIds = [];
489
+ const assignedQuery = {
490
+ clientId: requestData.clientId,
491
+ userEmail: getUserEmail,
492
+ };
493
+ const getAssignedType = await findOneUserAssignedStore( assignedQuery );
494
+ if ( getAssignedType ) {
495
+ if ( getAssignedType.userType == 'client' ) {
496
+ if ( getAssignedType.assignedType == 'group' ) {
497
+ groupIds = await getAssignedGroupIds( requestData.clientId, getUserEmail );
498
+ }
499
+ } else {
500
+ groupIds = [];
501
+ }
502
+ } else {
503
+ groupIds = [];
504
+ }
497
505
  }
498
506
  } else {
499
- if ( getUserType == 'tango' ) {
500
- groupIds = await getGroupIds( requestData.clientId );
501
- } else {
502
- return res.sendError( 'No User Assign', 400 );
503
- }
507
+ groupIds = [];
504
508
  }
505
509
 
506
510
  if ( groupIds && groupIds.length > 0 ) {
@@ -541,8 +545,9 @@ export const headerStoresV1 = async ( req, res ) => {
541
545
  let reqestData = req.body;
542
546
  let getUserEmail = req.user.email;
543
547
  let getUserType = req.user.userType;
548
+ let getRole = req.user.role;
544
549
  let getClientId = reqestData.clientId;
545
- let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
550
+ let totalStores = await getAllStores( getUserEmail, getClientId, getUserType, getRole );
546
551
  if ( totalStores && totalStores.length>0 ) {
547
552
  let storeQuery = [];
548
553
  if ( reqestData.city.length>0 && reqestData.group.length>0 ) {
@@ -605,7 +610,7 @@ export const headerStoresV1 = async ( req, res ) => {
605
610
  },
606
611
  ];
607
612
  } else {
608
- let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
613
+ let totalStores = await getAllStores( getUserEmail, getClientId, getUserType, getRole );
609
614
  storeQuery = [
610
615
  {
611
616
  $match: {
@@ -640,64 +645,59 @@ export const headerStoresV1 = async ( req, res ) => {
640
645
  }
641
646
  };
642
647
 
643
- async function getAllStores( getUserEmail, getClientId, getUserType ) {
648
+ async function getAllStores( getUserEmail, getClientId, getUserType, getRole ) {
644
649
  try {
645
- if ( getUserEmail && getUserEmail !='' ) {
646
- const assignedQuery = {
647
- clientId: getClientId,
648
- userEmail: getUserEmail,
649
- };
650
- const getAssignedType = await findOneUserAssignedStore( assignedQuery );
651
- if ( getAssignedType ) {
652
- if ( getAssignedType.userType == 'client' ) {
653
- if ( getAssignedType.assignedType && getAssignedType.assignedType !='' ) {
654
- let overAllStores = [];
655
- switch ( getAssignedType.assignedType ) {
656
- case 'store':
657
- let getAS = await getAssignedStores( getClientId, getUserEmail, 'store' );
658
- if ( getAS && getAS.length >0 ) {
659
- overAllStores = getAS;
660
- }
661
- break;
662
- case 'group':
663
- let getAGS = await getAssignedGroupStores( getClientId, getUserEmail, 'group' );
664
- if ( getAGS && getAGS.length >0 ) {
665
- overAllStores = getAGS;
666
- }
667
- break;
668
- case 'allstores':
669
- let getAllS = await getAssignedAllStores( getClientId );
670
- if ( getAllS && getAllS.length >0 ) {
671
- overAllStores = getAllS;
672
- }
673
- break;
674
- default:
675
- break;
676
- }
677
- return overAllStores;
678
- } else {
679
- return false;
680
- }
681
- } else if ( getAssignedType.userType == 'tango' ) {
682
- let overAllStores = [];
683
- let getAllS = await getAssignedAllStores( getClientId );
684
- if ( getAllS && getAllS.length >0 ) {
685
- overAllStores = getAllS;
686
- }
687
- return overAllStores;
688
- } else {
689
- return false;
650
+ if ( getUserEmail && getUserEmail !='' && getClientId && getClientId !='' && getUserType && getUserType !='' && getRole && getRole!='' ) {
651
+ let overAllStores = [];
652
+ if ( getUserType == 'tango' ) {
653
+ let getAllS = await getAssignedAllStores( getClientId );
654
+ if ( getAllS && getAllS.length >0 ) {
655
+ overAllStores = getAllS;
690
656
  }
691
- } else {
692
- if ( getUserType && getUserType == 'tango' ) {
693
- let overAllStores = [];
657
+ return overAllStores;
658
+ } else if ( getUserType == 'client' ) {
659
+ if ( getRole == 'superadmin' ) {
694
660
  let getAllS = await getAssignedAllStores( getClientId );
695
661
  if ( getAllS && getAllS.length >0 ) {
696
662
  overAllStores = getAllS;
697
663
  }
698
664
  return overAllStores;
699
665
  } else {
700
- return false;
666
+ const assignedQuery = {
667
+ clientId: getClientId,
668
+ userEmail: getUserEmail,
669
+ };
670
+ const getAssignedType = await findOneUserAssignedStore( assignedQuery );
671
+ if ( getAssignedType ) {
672
+ if ( getAssignedType.userType == 'client' ) {
673
+ if ( getAssignedType.assignedType && getAssignedType.assignedType !='' ) {
674
+ let overAllStores = [];
675
+ switch ( getAssignedType.assignedType ) {
676
+ case 'store':
677
+ let getAS = await getAssignedStores( getClientId, getUserEmail, 'store' );
678
+ if ( getAS && getAS.length >0 ) {
679
+ overAllStores = getAS;
680
+ }
681
+ break;
682
+ case 'group':
683
+ let getAGS = await getAssignedGroupStores( getClientId, getUserEmail, 'group' );
684
+ if ( getAGS && getAGS.length >0 ) {
685
+ overAllStores = getAGS;
686
+ }
687
+ break;
688
+ default:
689
+ break;
690
+ }
691
+ return overAllStores;
692
+ } else {
693
+ return false;
694
+ }
695
+ } else {
696
+ return false;
697
+ }
698
+ } else {
699
+ return false;
700
+ }
701
701
  }
702
702
  }
703
703
  } else {
@@ -1001,3 +1001,41 @@ async function getAssignedGroupIds( userClientId, getUserEmail ) {
1001
1001
  logger.error( { error: error, message: data, function: 'getAssignedGroupIds' } );
1002
1002
  }
1003
1003
  }
1004
+
1005
+ export async function isAllowedClient( req, res, next ) {
1006
+ try {
1007
+ let reqestData = req.body;
1008
+ let getUserEmail = req.user.email;
1009
+ let getUserType = req.user.userType;
1010
+ let getClientId = req.user.clientId;
1011
+ let getRole = req.user.role;
1012
+ if ( getUserType == 'tango' ) {
1013
+ if ( getRole == 'superadmin' ) {
1014
+ next();
1015
+ } else {
1016
+ const assignedQuery = {
1017
+ userEmail: getUserEmail,
1018
+ assignedType: 'client',
1019
+ assignedValue: reqestData.clientId,
1020
+ };
1021
+ const getAssignedType = await findOneUserAssignedStore( assignedQuery );
1022
+ if ( getAssignedType ) {
1023
+ next();
1024
+ } else {
1025
+ return res.sendError( 'Client Not Assigned', 400 );
1026
+ }
1027
+ }
1028
+ } else if ( getUserType == 'client' ) {
1029
+ if ( getClientId == reqestData.clientId ) {
1030
+ next();
1031
+ } else {
1032
+ return res.sendError( 'Client Not Assigned', 400 );
1033
+ }
1034
+ } else {
1035
+ return res.sendError( 'Client Not Assigned', 400 );
1036
+ }
1037
+ } catch ( error ) {
1038
+ logger.error( { error: error, function: 'isAllowedClient' } );
1039
+ return res.sendError( error, 500 );
1040
+ }
1041
+ }
@@ -0,0 +1,586 @@
1
+ import { logger } from 'tango-app-api-middleware';
2
+ // import * as clientService from '../services/clients.services.js';
3
+ import {
4
+ aggregateStore,
5
+ } from '../services/stores.service.js';
6
+ import { aggregateUserAssignedStore, findOneUserAssignedStore } from '../services/userAssignedStore.service.js';
7
+ import { aggregateGroup } from '../services/group.service.js';
8
+
9
+ export const headerLocationsV2 = async ( req, res ) => {
10
+ try {
11
+ let reqestData = req.body;
12
+ let getUserEmail = req.user.email;
13
+ let getUserType = req.user.userType;
14
+ let getClientId = reqestData.clientId;
15
+ let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
16
+ if ( totalStores && totalStores.length>0 ) {
17
+ let storeQuery = [
18
+ {
19
+ $match: {
20
+ $and: [
21
+ { clientId: { $eq: getClientId } },
22
+ { storeId: { $in: totalStores } },
23
+ ],
24
+ },
25
+ },
26
+ {
27
+ $group: {
28
+ _id: '$storeProfile.city',
29
+ },
30
+ },
31
+ {
32
+ $project: {
33
+ _id: 0,
34
+ city: '$_id',
35
+ },
36
+ },
37
+ {
38
+ $sort: {
39
+ city: -1,
40
+ },
41
+ },
42
+ ];
43
+ const cityList = await aggregateStore( storeQuery );
44
+ if ( cityList && cityList.length > 0 ) {
45
+ return res.sendSuccess( { locationData: cityList } );
46
+ } else {
47
+ return res.sendError( 'No City', 400 );
48
+ }
49
+ } else {
50
+ return res.sendError( 'No stores', 400 );
51
+ }
52
+ } catch ( error ) {
53
+ logger.error( { error: error, message: req.query, function: 'trafficCards' } );
54
+ return res.sendError( { error: error }, 500 );
55
+ }
56
+ };
57
+
58
+ export const headerGroupsV2 = async ( req, res ) => {
59
+ try {
60
+ let requestData = req.body;
61
+ let getUserEmail = req.user.email;
62
+ let getUserType = req.user.userType;
63
+ const assignedQuery = {
64
+ clientId: requestData.clientId,
65
+ userEmail: getUserEmail,
66
+ };
67
+ let groupIds;
68
+ const getAssignedType = await findOneUserAssignedStore( assignedQuery );
69
+ if ( getAssignedType ) {
70
+ if ( getAssignedType.userType == 'client' ) {
71
+ if ( getAssignedType.assignedType == 'allstores' ) {
72
+ groupIds = await getGroupIds( requestData.clientId );
73
+ } else if ( getAssignedType.assignedType == 'group' ) {
74
+ groupIds = await getAssignedGroupIds( requestData.clientId, getUserEmail );
75
+ }
76
+ } else if ( getAssignedType.userType == 'tango' ) {
77
+ groupIds = await getGroupIds( requestData.clientId );
78
+ } else {
79
+ groupIds = [];
80
+ }
81
+ } else {
82
+ if ( getUserType == 'tango' ) {
83
+ groupIds = await getGroupIds( requestData.clientId );
84
+ } else {
85
+ return res.sendError( 'No User Assign', 400 );
86
+ }
87
+ }
88
+
89
+ if ( groupIds && groupIds.length > 0 ) {
90
+ let groupQuery = [
91
+ {
92
+ $match: {
93
+ $and: [
94
+ { clientId: { $eq: requestData.clientId } },
95
+ { _id: { $in: groupIds } },
96
+ ],
97
+ },
98
+ },
99
+ {
100
+ $project: {
101
+ _id: 0,
102
+ groupName: 1,
103
+ },
104
+ },
105
+ ];
106
+ const groupResult = await aggregateGroup( groupQuery );
107
+ if ( groupResult && groupResult.length > 0 ) {
108
+ return res.sendSuccess( { groupData: groupResult } );
109
+ } else {
110
+ return res.sendError( 'No Group', 400 );
111
+ }
112
+ } else {
113
+ return res.sendError( 'No Group', 400 );
114
+ }
115
+ } catch ( error ) {
116
+ console.log( 'error =>', error );
117
+ logger.error( { error: error, message: req.query, function: 'trafficCards' } );
118
+ return res.sendError( { error: error }, 500 );
119
+ }
120
+ };
121
+
122
+ export const headerStoresV2 = async ( req, res ) => {
123
+ try {
124
+ let reqestData = req.body;
125
+ let getUserEmail = req.user.email;
126
+ let getUserType = req.user.userType;
127
+ let getClientId = reqestData.clientId;
128
+ let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
129
+ if ( totalStores && totalStores.length>0 ) {
130
+ let storeQuery = [];
131
+ if ( reqestData.city.length>0 && reqestData.group.length>0 ) {
132
+ let unqueCityStores = await getLocationStores( getClientId, reqestData.city );
133
+ let unqueGroupStores = await getGroupStores( getClientId, reqestData.group );
134
+ storeQuery = [
135
+ {
136
+ $match: {
137
+ $and: [
138
+ { storeId: { $in: totalStores } },
139
+ { storeId: { $in: unqueCityStores } },
140
+ { storeId: { $in: unqueGroupStores } },
141
+ ],
142
+ },
143
+ },
144
+ {
145
+ $project: {
146
+ _id: 0,
147
+ storeId: '$storeId',
148
+ storeName: '$storeName',
149
+ },
150
+ },
151
+ ];
152
+ } else if ( reqestData.city.length>0 ) {
153
+ let unqueCityStores = await getLocationStores( getClientId, reqestData.city );
154
+ storeQuery = [
155
+ {
156
+ $match: {
157
+ $and: [
158
+ { storeId: { $in: totalStores } },
159
+ { storeId: { $in: unqueCityStores } },
160
+ ],
161
+ },
162
+ },
163
+ {
164
+ $project: {
165
+ _id: 0,
166
+ storeId: '$storeId',
167
+ storeName: '$storeName',
168
+ },
169
+ },
170
+ ];
171
+ } else if ( reqestData.group.length>0 ) {
172
+ let unqueGroupStores = await getGroupStores( getClientId, reqestData.group );
173
+ storeQuery = [
174
+ {
175
+ $match: {
176
+ $and: [
177
+ { storeId: { $in: totalStores } },
178
+ { storeId: { $in: unqueGroupStores } },
179
+ ],
180
+ },
181
+ },
182
+ {
183
+ $project: {
184
+ _id: 0,
185
+ storeId: '$storeId',
186
+ storeName: '$storeName',
187
+ },
188
+ },
189
+ ];
190
+ } else {
191
+ let totalStores = await getAllStores( getUserEmail, getClientId, getUserType );
192
+ storeQuery = [
193
+ {
194
+ $match: {
195
+ $and: [
196
+ { storeId: { $in: totalStores } },
197
+ ],
198
+ },
199
+ },
200
+ {
201
+ $project: {
202
+ _id: 0,
203
+ storeId: '$storeId',
204
+ storeName: '$storeName',
205
+ },
206
+ },
207
+ ];
208
+ }
209
+
210
+ const storeList = await aggregateStore( storeQuery );
211
+ if ( storeList && storeList.length > 0 ) {
212
+ return res.sendSuccess( { storesData: storeList } );
213
+ } else {
214
+ return res.sendError( 'No Stores', 400 );
215
+ }
216
+ } else {
217
+ return res.sendError( 'No Stores', 400 );
218
+ }
219
+ } catch ( error ) {
220
+ console.log( 'headerStoresV1 =>', error );
221
+ logger.error( { error: error, message: req.query, function: 'headerStoresV1' } );
222
+ return res.sendError( { error: error }, 500 );
223
+ }
224
+ };
225
+
226
+ async function getAllStores( getUserEmail, getClientId, getUserType ) {
227
+ try {
228
+ if ( getUserEmail && getUserEmail !='' ) {
229
+ const assignedQuery = {
230
+ clientId: getClientId,
231
+ userEmail: getUserEmail,
232
+ };
233
+ const getAssignedType = await findOneUserAssignedStore( assignedQuery );
234
+ if ( getAssignedType ) {
235
+ if ( getAssignedType.userType == 'client' ) {
236
+ if ( getAssignedType.assignedType && getAssignedType.assignedType !='' ) {
237
+ let overAllStores = [];
238
+ switch ( getAssignedType.assignedType ) {
239
+ case 'store':
240
+ let getAS = await getAssignedStores( getClientId, getUserEmail, 'store' );
241
+ if ( getAS && getAS.length >0 ) {
242
+ overAllStores = getAS;
243
+ }
244
+ break;
245
+ case 'group':
246
+ let getAGS = await getAssignedGroupStores( getClientId, getUserEmail, 'group' );
247
+ if ( getAGS && getAGS.length >0 ) {
248
+ overAllStores = getAGS;
249
+ }
250
+ break;
251
+ case 'allstores':
252
+ let getAllS = await getAssignedAllStores( getClientId );
253
+ if ( getAllS && getAllS.length >0 ) {
254
+ overAllStores = getAllS;
255
+ }
256
+ break;
257
+ default:
258
+ break;
259
+ }
260
+ return overAllStores;
261
+ } else {
262
+ return false;
263
+ }
264
+ } else if ( getAssignedType.userType == 'tango' ) {
265
+ let overAllStores = [];
266
+ let getAllS = await getAssignedAllStores( getClientId );
267
+ if ( getAllS && getAllS.length >0 ) {
268
+ overAllStores = getAllS;
269
+ }
270
+ return overAllStores;
271
+ } else {
272
+ return false;
273
+ }
274
+ } else {
275
+ if ( getUserType && getUserType == 'tango' ) {
276
+ let overAllStores = [];
277
+ let getAllS = await getAssignedAllStores( getClientId );
278
+ if ( getAllS && getAllS.length >0 ) {
279
+ overAllStores = getAllS;
280
+ }
281
+ return overAllStores;
282
+ } else {
283
+ return false;
284
+ }
285
+ }
286
+ } else {
287
+ return false;
288
+ }
289
+ } catch ( error ) {
290
+ console.log( 'getAllStores =>', error );
291
+ logger.error( { error: error, message: req.query, function: 'getAllStores' } );
292
+ }
293
+ };
294
+
295
+ async function getAssignedStores( clientId, userEmail, assignedType ) {
296
+ try {
297
+ if ( clientId && clientId !='' && userEmail && userEmail !='' && assignedType && assignedType !='' ) {
298
+ let storeQuery = [
299
+ {
300
+ $match: {
301
+ $and: [
302
+ { clientId: { $eq: clientId } },
303
+ { userEmail: { $eq: userEmail } },
304
+ { assignedType: { $eq: assignedType } },
305
+ ],
306
+ },
307
+ },
308
+ {
309
+ $group: {
310
+ _id: null,
311
+ stores: { $push: '$assignedValue' },
312
+ },
313
+ },
314
+ ];
315
+ const storeList = await aggregateUserAssignedStore( storeQuery );
316
+ if ( storeList && storeList.length>0 && storeList[0]?.stores.length > 0 ) {
317
+ let uniqueStores = [ ...new Set( storeList[0].stores ) ];
318
+ return uniqueStores;
319
+ } else {
320
+ return false;
321
+ }
322
+ } else {
323
+ return false;
324
+ }
325
+ } catch ( error ) {
326
+ console.log( 'getAssignedStores error =>', error );
327
+ logger.error( { error: error, message: data, function: 'getAssignedStores' } );
328
+ }
329
+ }
330
+
331
+ async function getAssignedGroupStores( clientId, userEmail, assignedType ) {
332
+ try {
333
+ if ( clientId && clientId !='' && userEmail && userEmail !='' && assignedType && assignedType !='' ) {
334
+ const groupQuery = [
335
+ {
336
+ $match: {
337
+ $and: [
338
+ { clientId: { $eq: clientId } },
339
+ { userEmail: { $eq: userEmail } },
340
+ { assignedType: { $eq: assignedType } },
341
+ ],
342
+ },
343
+ },
344
+ {
345
+ $lookup: {
346
+ from: 'groups',
347
+ let: { groupId: { $toObjectId: '$assignedValue' } },
348
+ pipeline: [
349
+ {
350
+ $match: {
351
+ $expr: {
352
+ $eq: [ '$_id', '$$groupId' ],
353
+ },
354
+ },
355
+ },
356
+ {
357
+ $project: {
358
+ _id: 0,
359
+ storeList: 1,
360
+ },
361
+ },
362
+ ], as: 'groups',
363
+ },
364
+ },
365
+ {
366
+ $unwind: {
367
+ path: '$groups', preserveNullAndEmptyArrays: true,
368
+ },
369
+ },
370
+ {
371
+ $unwind: {
372
+ path: '$groups.storeList', preserveNullAndEmptyArrays: true,
373
+ },
374
+ },
375
+ {
376
+ $group: {
377
+ _id: null,
378
+ stores: { $push: '$groups.storeList' },
379
+ },
380
+ },
381
+ ];
382
+ const groupStoreList = await aggregateUserAssignedStore( groupQuery );
383
+ if ( groupStoreList && groupStoreList.length>0 && groupStoreList[0]?.stores.length > 0 ) {
384
+ let uniqueStores = [ ...new Set( groupStoreList[0].stores ) ];
385
+ return uniqueStores;
386
+ } else {
387
+ return false;
388
+ }
389
+ } else {
390
+ return false;
391
+ }
392
+ } catch ( error ) {
393
+ console.log( 'getAssignedGroupStores error =>', error );
394
+ logger.error( { error: error, message: data, function: 'getAssignedGroupStores' } );
395
+ }
396
+ }
397
+
398
+ async function getAssignedAllStores( userClientId ) {
399
+ try {
400
+ if ( userClientId && userClientId !='' ) {
401
+ let storeQuery = [
402
+ {
403
+ $match: {
404
+ $and: [
405
+ { clientId: { $eq: userClientId } },
406
+ { status: { $eq: 'active' } },
407
+ ],
408
+ },
409
+ },
410
+ {
411
+ $group: {
412
+ _id: null,
413
+ stores: { $push: '$storeId' },
414
+ },
415
+ },
416
+ ];
417
+ const storeList = await aggregateStore( storeQuery );
418
+ if ( storeList && storeList.length>0 && storeList[0]?.stores.length > 0 ) {
419
+ let uniqueStores = [ ...new Set( storeList[0].stores ) ];
420
+ return uniqueStores;
421
+ } else {
422
+ return false;
423
+ }
424
+ } else {
425
+ return false;
426
+ }
427
+ } catch ( error ) {
428
+ console.log( 'getAssignedAllStores error =>', error );
429
+ logger.error( { error: error, message: data, function: 'getAssignedAllStores' } );
430
+ }
431
+ }
432
+
433
+ async function getGroupStores( userClientId, groupList ) {
434
+ try {
435
+ if ( userClientId && userClientId !='' && groupList && groupList.length >0 ) {
436
+ let groupQuery = [
437
+ {
438
+ $match: {
439
+ $and: [
440
+ { clientId: { $eq: userClientId } },
441
+ { groupName: { $in: groupList } },
442
+ ],
443
+ },
444
+ },
445
+ {
446
+ $unwind: {
447
+ path: '$storeList', preserveNullAndEmptyArrays: true,
448
+ },
449
+ },
450
+ {
451
+ $group: {
452
+ _id: null,
453
+ stores: { $push: '$storeList' },
454
+ },
455
+ },
456
+ ];
457
+ const groupStoreList = await aggregateGroup( groupQuery );
458
+ if ( groupStoreList && groupStoreList.length>0 && groupStoreList[0]?.stores.length > 0 ) {
459
+ let uniqueStores = [ ...new Set( groupStoreList[0].stores ) ];
460
+ return uniqueStores;
461
+ } else {
462
+ return false;
463
+ }
464
+ } else {
465
+ return false;
466
+ }
467
+ } catch ( error ) {
468
+ console.log( 'getGroupStores error =>', error );
469
+ logger.error( { error: error, message: data, function: 'getGroupStores' } );
470
+ }
471
+ }
472
+
473
+ async function getLocationStores( userClientId, cityList ) {
474
+ try {
475
+ if ( userClientId && userClientId !='' && cityList && cityList.length >0 ) {
476
+ let storeQuery = [
477
+ {
478
+ $match: {
479
+ $and: [
480
+ { clientId: { $eq: userClientId } },
481
+ { 'storeProfile.city': { $in: cityList } },
482
+ ],
483
+ },
484
+ },
485
+ {
486
+ $project: {
487
+ _id: 0,
488
+ storeId: '$storeId',
489
+ },
490
+ },
491
+ {
492
+ $group: {
493
+ _id: null,
494
+ stores: { $push: '$storeId' },
495
+ },
496
+ },
497
+ ];
498
+ const cityStoreList = await aggregateStore( storeQuery );
499
+ if ( cityStoreList && cityStoreList.length>0 && cityStoreList[0]?.stores.length > 0 ) {
500
+ let uniqueStores = [ ...new Set( cityStoreList[0].stores ) ];
501
+ return uniqueStores;
502
+ } else {
503
+ return false;
504
+ }
505
+ } else {
506
+ return false;
507
+ }
508
+ } catch ( error ) {
509
+ console.log( 'getLocationStores error =>', error );
510
+ logger.error( { error: error, message: data, function: 'getLocationStores' } );
511
+ }
512
+ }
513
+
514
+ async function getGroupIds( userClientId ) {
515
+ try {
516
+ if ( userClientId && userClientId !='' ) {
517
+ let groupQuery = [
518
+ {
519
+ $match: {
520
+ $and: [
521
+ { clientId: { $eq: userClientId } },
522
+ ],
523
+ },
524
+ },
525
+ {
526
+ $group: {
527
+ _id: null,
528
+ groupName: { $push: '$_id' },
529
+ },
530
+ },
531
+ ];
532
+ const groupGroupIds = await aggregateGroup( groupQuery );
533
+ if ( groupGroupIds && groupGroupIds.length>0 && groupGroupIds[0]?.groupName.length > 0 ) {
534
+ let uniqueGroupIds = [ ...new Set( groupGroupIds[0].groupName ) ];
535
+ return uniqueGroupIds;
536
+ } else {
537
+ return false;
538
+ }
539
+ } else {
540
+ return false;
541
+ }
542
+ } catch ( error ) {
543
+ console.log( 'getGroupIds error =>', error );
544
+ logger.error( { error: error, message: data, function: 'getGroupIds' } );
545
+ }
546
+ }
547
+
548
+ async function getAssignedGroupIds( userClientId, getUserEmail ) {
549
+ try {
550
+ if ( userClientId && userClientId !='' && getUserEmail && getUserEmail !='' ) {
551
+ let groupQuery = [
552
+ {
553
+ $match: {
554
+ $and: [
555
+ { clientId: { $eq: userClientId } },
556
+ { userEmail: { $eq: getUserEmail } },
557
+ { assignedType: { $eq: 'group' } },
558
+ ],
559
+ },
560
+ },
561
+ {
562
+ $group: {
563
+ _id: null,
564
+ groupName: { $push: '$assignedValue' },
565
+ },
566
+ },
567
+ ];
568
+ const groupStoreList = await aggregateUserAssignedStore( groupQuery );
569
+ if ( groupStoreList && groupStoreList.length>0 && groupStoreList[0]?.groupName.length > 0 ) {
570
+ let uniqueGroupIdsData = [ ...new Set( groupStoreList[0].groupName ) ];
571
+ let uniqueGroupIds = [];
572
+ for ( let i = 0; i < uniqueGroupIdsData.length; i++ ) {
573
+ uniqueGroupIds.push( new ObjectId( uniqueGroupIdsData[i] ) );
574
+ }
575
+ return uniqueGroupIds;
576
+ } else {
577
+ return false;
578
+ }
579
+ } else {
580
+ return false;
581
+ }
582
+ } catch ( error ) {
583
+ console.log( 'getAssignedGroupIds error =>', error );
584
+ logger.error( { error: error, message: data, function: 'getAssignedGroupIds' } );
585
+ }
586
+ }
@@ -50,6 +50,7 @@ import {
50
50
  headerStoresV1,
51
51
  headerLocationsV1,
52
52
  headerGroupsV1,
53
+ isAllowedClient,
53
54
  } from '../controllers/tangoTrafficV1.controllers.js';
54
55
 
55
56
 
@@ -76,102 +77,102 @@ analysisTrafficRouter
76
77
  .post( '/headerLocations', headerLocations )
77
78
  .post( '/headerGroups', headerGroups )
78
79
  .post( '/headerStores', headerStores )
79
- .post( '/cardsFunnel_v1', isAllowedSessionHandler, authorize( {
80
+ .post( '/cardsFunnel_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
80
81
  userType: [ 'tango', 'client' ], access: [
81
82
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
82
83
  ],
83
84
  } ), validate( validationDtos.validateCardFunnelParams ), cardsFunnelV1 )
84
- .post( '/cardsGraphs_v1', isAllowedSessionHandler, authorize( {
85
+ .post( '/cardsGraphs_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
85
86
  userType: [ 'tango', 'client' ], access: [
86
87
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
87
88
  ],
88
89
  } ), validate( validationDtos.validateCardGraphParams ), cardsGraphsV1 )
89
- .post( '/recapVideo_v1', isAllowedSessionHandler, authorize( {
90
+ .post( '/recapVideo_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
90
91
  userType: [ 'tango', 'client' ], access: [
91
92
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
92
93
  ],
93
94
  } ), validate( validationDtos.validateRecapVideoParams ), recapVideoV1 )
94
- .post( '/densityDwell_v1', isAllowedSessionHandler, authorize( {
95
+ .post( '/densityDwell_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
95
96
  userType: [ 'tango', 'client' ], access: [
96
97
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
97
98
  ],
98
99
  } ), validate( validationDtos.validateDensityDwellParams ), densityDwellV1 )
99
- .post( '/overallCards_v1', isAllowedSessionHandler, authorize( {
100
+ .post( '/overallCards_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
100
101
  userType: [ 'tango', 'client' ], access: [
101
102
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
102
103
  ],
103
104
  } ), validate( validationDtos.validateOverallCardsParams ), overallCardsV1 )
104
- .post( '/overallHourlyChart_v1', isAllowedSessionHandler, authorize( {
105
+ .post( '/overallHourlyChart_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
105
106
  userType: [ 'tango', 'client' ], access: [
106
107
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
107
108
  ],
108
109
  } ), validate( validationDtos.validateOverallHourlyChartParams ), overallHourlyChartV1 )
109
- .post( '/overallChart_v1', isAllowedSessionHandler, authorize( {
110
+ .post( '/overallChart_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
110
111
  userType: [ 'tango', 'client' ], access: [
111
112
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
112
113
  ],
113
114
  } ), validate( validationDtos.validateOverallCharParams ), overallChartV1 )
114
- .post( '/singleStoreChart_v1', isAllowedSessionHandler, authorize( {
115
+ .post( '/singleStoreChart_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
115
116
  userType: [ 'tango', 'client' ], access: [
116
117
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
117
118
  ],
118
119
  } ), validate( validationDtos.validateSingleStoreChartParams ), singleStoreChartV1 )
119
- .post( '/demographicChart_v1', isAllowedSessionHandler, authorize( {
120
+ .post( '/demographicChart_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
120
121
  userType: [ 'tango', 'client' ], access: [
121
122
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
122
123
  ],
123
124
  } ), validate( validationDtos.validateDemographicChartParams ), demographicChartV1 )
124
- .post( '/buyerChart_v1', isAllowedSessionHandler, authorize( {
125
+ .post( '/buyerChart_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
125
126
  userType: [ 'tango', 'client' ], access: [
126
127
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
127
128
  ],
128
129
  } ), validate( validationDtos.validateBuyerChartParams ), buyerChartV1 )
129
- .post( '/footfallDirectoryFolders_v1', isAllowedSessionHandler, authorize( {
130
+ .post( '/footfallDirectoryFolders_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
130
131
  userType: [ 'tango', 'client' ], access: [
131
132
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
132
133
  ],
133
134
  } ), validate( validationDtos.validateFootfallDirectoryFoldersParams ), footfallDirectoryFoldersV1 )
134
- .post( '/footfallDirectory_v1', isAllowedSessionHandler, authorize( {
135
+ .post( '/footfallDirectory_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
135
136
  userType: [ 'tango', 'client' ], access: [
136
137
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
137
138
  ],
138
139
  } ), validate( validationDtos.validateFootfallDirectoryParams ), footfallDirectoryV1 )
139
- .post( '/summaryTable_v1', isAllowedSessionHandler, authorize( {
140
+ .post( '/summaryTable_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
140
141
  userType: [ 'tango', 'client' ], access: [
141
142
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
142
143
  ],
143
144
  } ), validate( validationDtos.validateSummaryTableParams ), summaryTableV1 )
144
- .post( '/footfallTrend_v1', isAllowedSessionHandler, authorize( {
145
+ .post( '/footfallTrend_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
145
146
  userType: [ 'tango', 'client' ], access: [
146
147
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
147
148
  ],
148
149
  } ), validate( validationDtos.validateFootfallTrendParams ), footfallTrendV1 )
149
- .post( '/storeOperation_v1', isAllowedSessionHandler, authorize( {
150
+ .post( '/storeOperation_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
150
151
  userType: [ 'tango', 'client' ], access: [
151
152
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
152
153
  ],
153
154
  } ), validate( validationDtos.validateStoreOperationParams ), storeOperationV1 )
154
- .post( '/performanceMatrix_v1', isAllowedSessionHandler, authorize( {
155
+ .post( '/performanceMatrix_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
155
156
  userType: [ 'tango', 'client' ], access: [
156
157
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
157
158
  ],
158
159
  } ), validate( validationDtos.validateperformanceMatrixParams ), performanceMatrixV1 )
159
- .post( '/storesMap_v1', isAllowedSessionHandler, authorize( {
160
+ .post( '/storesMap_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
160
161
  userType: [ 'tango', 'client' ], access: [
161
162
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
162
163
  ],
163
164
  } ), validate( validationDtos.validateStoresMapParams ), storesMapV1 )
164
- .post( '/headerLocations_v1', isAllowedSessionHandler, authorize( {
165
+ .post( '/headerLocations_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
165
166
  userType: [ 'tango', 'client' ], access: [
166
167
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
167
168
  ],
168
169
  } ), validate( validationDtos.validateHeaderParams ), headerLocationsV1 )
169
- .post( '/headerGroups_v1', isAllowedSessionHandler, authorize( {
170
+ .post( '/headerGroups_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
170
171
  userType: [ 'tango', 'client' ], access: [
171
172
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
172
173
  ],
173
174
  } ), validate( validationDtos.validateHeaderParams ), headerGroupsV1 )
174
- .post( '/headerStores_v1', isAllowedSessionHandler, authorize( {
175
+ .post( '/headerStores_v1', isAllowedSessionHandler, isAllowedClient, authorize( {
175
176
  userType: [ 'tango', 'client' ], access: [
176
177
  { featureName: 'analytics', name: 'tangoTraffic', permissions: [ 'isView' ] },
177
178
  ],