tango-app-api-trax 3.2.1 → 3.3.1-airtel-0

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.2.1",
3
+ "version": "3.3.1-airtel-0",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.2.16",
30
- "tango-app-api-middleware": "^3.1.50",
29
+ "tango-api-schema": "^2.2.91",
30
+ "tango-app-api-middleware": "^3.1.70",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
33
33
  "winston-daily-rotate-file": "^5.0.0"
@@ -5,7 +5,7 @@ import * as processedchecklistService from '../services/processedchecklist.servi
5
5
  import * as processedTaskService from '../services/processedTaskList.service.js';
6
6
  import * as taskConfigService from '../services/taskConfig.service.js';
7
7
  import * as checklistService from '../services/checklist.service.js';
8
- // import * as processedTaskconfigService from '../services/processedTaskConfig.service.js';
8
+ import * as processedcheklistconfigService from '../services/processedchecklistconfig.services.js';
9
9
  import * as clientService from '../services/clients.services.js';
10
10
  import * as storeService from '../services/store.service.js';
11
11
 
@@ -42,26 +42,46 @@ export const downloadInsert = async ( req, res ) => {
42
42
  }
43
43
  }
44
44
  }
45
+ console.log( requestData );
45
46
 
46
47
  if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id != '' ) {
47
48
  let getChecklistQuery = [];
48
- getChecklistQuery.push( { $project: { sourceCheckList_id: 1, date_iso: 1, store_id: 1, checklistStatus: 1, redoStatus: 1 } } );
49
- getChecklistQuery.push( {
50
- $match: {
51
- $and: [
52
- { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
53
- { date_iso: { $gte: fromDate, $lte: toDate } },
54
- { store_id: { $in: requestData.storeIds } },
55
- ],
56
- $or: [
57
- { checklistStatus: 'submit' },
58
- { redoStatus: true },
59
- ],
60
- },
61
- } );
49
+ getChecklistQuery.push( { $project: { sourceCheckList_id: 1, date_iso: 1, store_id: 1, userEmail: 1, checklistStatus: 1, redoStatus: 1 } } );
50
+
51
+ if ( requestData.filtertype ==='Clusters' ) {
52
+ getChecklistQuery.push( {
53
+ $match: {
54
+ $and: [
55
+ { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
56
+ { date_iso: { $gte: fromDate, $lte: toDate } },
57
+ { store_id: { $in: requestData.storeIds } },
58
+ ],
59
+ $or: [
60
+ { checklistStatus: 'submit' },
61
+ { redoStatus: true },
62
+ ],
63
+ },
64
+ } );
65
+ } else {
66
+ console.log( requestData );
67
+ getChecklistQuery.push( {
68
+ $match: {
69
+ $and: [
70
+ { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
71
+ { date_iso: { $gte: fromDate, $lte: toDate } },
72
+ { userEmail: { $in: requestData.userEmailList } },
73
+ ],
74
+ $or: [
75
+ { checklistStatus: 'submit' },
76
+ { redoStatus: true },
77
+ ],
78
+ },
79
+ } );
80
+ }
62
81
  getChecklistQuery.push( { $count: 'totalCount' } );
63
82
 
64
83
  let getChecklistCount = await processedchecklistService.aggregate( getChecklistQuery );
84
+ console.log( getChecklistCount );
65
85
  if ( requestData.insertType === 'task' ) {
66
86
  getChecklistCount = await processedTaskService.aggregate( getChecklistQuery );
67
87
  }
@@ -121,8 +141,11 @@ export const downloadInsert = async ( req, res ) => {
121
141
  'searchValue': requestData.searchValue || '',
122
142
  'insertType': requestData.insertType || '',
123
143
  'viewRedo': requestData.viewRedo || false,
124
-
144
+ 'userEmailList': requestData.userEmailList || [],
145
+ 'filtertype': requestData.filtertype || 'Clusters',
146
+ 'checkListType': requestData.checkListType,
125
147
  };
148
+ console.log( insertData );
126
149
  let resultData = await downloadService.insert( insertData );
127
150
  if ( resultData ) {
128
151
  let sqsMessageRequestData = {
@@ -149,6 +172,101 @@ export const downloadInsert = async ( req, res ) => {
149
172
  return res.sendError( e, 500 );
150
173
  }
151
174
  };
175
+ export const downloadInsertAI = async ( req, res ) => {
176
+ try {
177
+ let requestData = req.body;
178
+ let name;
179
+ let fileType = requestData?.fileType || 'pdfzip';
180
+
181
+
182
+ if ( requestData.fileType == 'pdf' ) {
183
+ if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
184
+ fileType = 'pdfzip';
185
+ }
186
+ if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
187
+ fileType = 'pdfzip';
188
+ }
189
+ }
190
+
191
+ if ( requestData.checklistName != '' ) {
192
+ name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
193
+ if ( requestData?.toDate ) {
194
+ name = name + '-' + dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
195
+ }
196
+ let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
197
+ let type = requestData.fileType || 'pdfzip';
198
+ let downloadDetails = await downloadService.getCount( { $and: [ { $or: [ { name: { $regex: regexName } }, { name: name } ] }, { fileType: type } ] } );
199
+ if ( downloadDetails ) {
200
+ name = name + ' (' + downloadDetails + ')';
201
+ }
202
+ } else {
203
+ name = requestData?.checklistName;
204
+ }
205
+
206
+
207
+ let findchecklist = await processedcheklistconfigService.findOne( { 'checkListType': requestData.checkListType, 'client_id': requestData.clientId } ).sort( { _id: -1 } );
208
+
209
+ console.log( findchecklist );
210
+ name = name + '-' + requestData.fileType;
211
+ let insertData = {
212
+ 'date_string': requestData.fromDate || '',
213
+ 'sourceCheckList_id': requestData?.sourceCheckList_id || '',
214
+ 'checklistIdList': requestData?.checklistId || [],
215
+ 'status': 'inprogress',
216
+ 'client_id': requestData.clientId || '',
217
+ 'date_iso': new Date( requestData.fromDate ) || '',
218
+ 'createdBy': req.user._id || '',
219
+ 'name': name,
220
+ 'fileType': fileType,
221
+ 'storeIds': requestData.storeIds || [],
222
+ 'questions': requestData.questions || [],
223
+ 'fromDate': requestData.fromDate || '',
224
+ 'toDate': requestData.toDate || '',
225
+ 'previewType': requestData.previewType || '',
226
+ 'viewFlag': requestData.viewFlag || false,
227
+ 'userEmail': req.user.email || '',
228
+ 'createdBy': req.user._id || '',
229
+ 'downloadInsertFrom': requestData.downloadInsertFrom || '',
230
+ 'answerType': requestData.answerType || '',
231
+ 'searchValue': requestData.searchValue || '',
232
+ 'insertType': requestData.insertType || '',
233
+ 'viewRedo': requestData.viewRedo || false,
234
+ 'userEmailList': requestData.userEmailList || [],
235
+ 'filtertype': requestData.filtertype || 'Clusters',
236
+ 'checkListType': requestData.checkListType,
237
+ 'checkListName': findchecklist.checkListName,
238
+ 'checkListDescription': findchecklist.checkListDescription,
239
+
240
+ };
241
+ console.log( requestData );
242
+ console.log( insertData );
243
+
244
+ let resultData = await downloadService.insert( insertData );
245
+ if ( resultData ) {
246
+ let sqsMessageRequestData = {
247
+ 'zipId': resultData._id,
248
+ 'fileType': fileType || 'zip',
249
+ 'storeId': requestData.storeIds || [],
250
+ };
251
+ if ( fileType === 'csv' || fileType === 'pdf' || fileType === 'csvzip' || fileType === 'pdfzip' || fileType === 'zipfiles' ) {
252
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
253
+ console.log( 'Send SQS Message CSV/PDF=>', msg );
254
+ }
255
+
256
+ if ( fileType === 'ppt' || fileType === 'pptzip' ) {
257
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
258
+ console.log( 'Send SQS Message PPT=>', msg );
259
+ }
260
+
261
+ res.sendSuccess( 'Success' );
262
+ } else {
263
+ return res.sendError( 'something went wrong, please try again', 500 );
264
+ }
265
+ } catch ( e ) {
266
+ console.log( 'insertdownloadRequest =>', e );
267
+ return res.sendError( e, 500 );
268
+ }
269
+ };
152
270
 
153
271
  export const downloadInsertOld = async ( req, res ) => {
154
272
  try {
@@ -418,6 +536,8 @@ export const getChecklistFromZipId = async ( req, res ) => {
418
536
  resultData.storeIds = getzipdata.storeIds;
419
537
  resultData.questions = getzipdata.questions;
420
538
  resultData.fileType = getzipdata.fileType;
539
+ resultData.userEmailList = getzipdata.userEmailList;
540
+ resultData.filtertype = getzipdata.filtertype;
421
541
  resultData.viewFlag = getzipdata.viewFlag;
422
542
  resultData.previewType = getzipdata.previewType || '';
423
543
  resultData.answerType = getzipdata.answerType || '';
@@ -11,6 +11,8 @@ import * as ApproverModel from '../services/approver.service.js';
11
11
 
12
12
  import mongoose from 'mongoose';
13
13
  import dayjs from 'dayjs';
14
+ import { aggregateTeams, findteams } from '../services/teams.service.js';
15
+ import { aggregate } from '../services/user.service.js';
14
16
  // import axios from 'axios';
15
17
  async function LamdaServiceCall( url, data ) {
16
18
  try {
@@ -132,7 +134,7 @@ export async function getcustomerunattendedlist( req, res ) {
132
134
  export async function storesList( req, res ) {
133
135
  try {
134
136
  let storeslist = await storeService.find( { clientId: req.body.clientId }, { storeId: 1, storeName: 1 } );
135
- if ( req.body.groups&&req.body.groups.length>0 ) {
137
+ if ( req.body.groups && req.body.groups.length > 0 ) {
136
138
  let stores = [];
137
139
  for ( let group of req.body.groups ) {
138
140
  let findGroup = await groupService.findOneGroup( { groupName: group.groupName }, { storeList: 1 } );
@@ -150,7 +152,7 @@ export async function storesList( req, res ) {
150
152
  export const checklistDropdown = async ( req, res ) => {
151
153
  try {
152
154
  let requestData = req.body;
153
- // let fromDate = new Date( requestData.fromDate );
155
+ let fromDate = new Date( requestData.fromDate );
154
156
  let toDate = new Date( requestData.toDate );
155
157
  let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
156
158
  toDate = new Date( toDate.getTime() - userTimezoneOffset );
@@ -161,8 +163,8 @@ export const checklistDropdown = async ( req, res ) => {
161
163
  let findAndQuery = [];
162
164
  findAndQuery.push(
163
165
  { client_id: requestData.clientId },
164
- // { date_iso: { $gte: fromDate } },
165
- // { date_iso: { $lte: toDate } },
166
+ { date_iso: { $gte: fromDate } },
167
+ { date_iso: { $lte: toDate } },
166
168
  // { checkListType: { $eq: 'custom' } },
167
169
  );
168
170
 
@@ -178,6 +180,8 @@ export const checklistDropdown = async ( req, res ) => {
178
180
  scheduleRepeatedType: 1,
179
181
  scheduleStartTime: 1,
180
182
  scheduleEndTime: 1,
183
+ coverage: 1,
184
+
181
185
  },
182
186
  } );
183
187
 
@@ -192,6 +196,7 @@ export const checklistDropdown = async ( req, res ) => {
192
196
  scheduleRepeatedType: { $last: '$scheduleRepeatedType' },
193
197
  scheduleStartTime: { $last: '$scheduleStartTime' },
194
198
  scheduleEndTime: { $last: '$scheduleEndTime' },
199
+ coverage: { $last: '$coverage' },
195
200
  },
196
201
  } );
197
202
 
@@ -230,6 +235,7 @@ export const checklistDropdown = async ( req, res ) => {
230
235
  scheduleRepeatedType: 1,
231
236
  scheduleStartTime: 1,
232
237
  scheduleEndTime: 1,
238
+ coverage: 1,
233
239
  checkListDescription: '$checklistconfigs.checkListDescription',
234
240
  publish: '$checklistconfigs.publish',
235
241
  },
@@ -240,7 +246,7 @@ export const checklistDropdown = async ( req, res ) => {
240
246
  return res.sendError( { error: 'No Data Found' }, 204 );
241
247
  }
242
248
 
243
- if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
249
+ if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy != '' ) {
244
250
  findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
245
251
  } else {
246
252
  findQuery.push( { $sort: { ['checkListName']: -1 } } );
@@ -248,8 +254,8 @@ export const checklistDropdown = async ( req, res ) => {
248
254
 
249
255
  let getChecklistData = await processedchecklistconfigService.aggregate( findQuery );
250
256
 
251
- let AiCheklist = getChecklistData.filter( ( data ) => data.checkListType!='custom'&& data.publish== true );
252
- let CustomCheklist = getChecklistData.filter( ( data ) => data.checkListType=='custom' );
257
+ let AiCheklist = getChecklistData.filter( ( data ) => data.checkListType != 'custom' );
258
+ let CustomCheklist = getChecklistData.filter( ( data ) => data.checkListType == 'custom' );
253
259
 
254
260
 
255
261
  AiCheklist.forEach( ( data ) => {
@@ -285,12 +291,14 @@ export async function approveChecklist( req, res ) {
285
291
  let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
286
292
  if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
287
293
  let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
288
- console.log( inputstores );
294
+
295
+
289
296
  let params = {
290
297
  'payload': {
291
298
  sourceCheckList_id: req.body.sourceCheckList_id,
292
299
  fromDate: req.body.fromDate,
293
300
  toDate: req.body.toDate,
301
+ filtertype: req.body.filtertype,
294
302
  store_id: inputstores,
295
303
  },
296
304
  'upsert': {
@@ -308,10 +316,10 @@ export async function approveChecklist( req, res ) {
308
316
  let url = JSON.parse( process.env.LAMBDAURL );
309
317
  let searchResponse = await fetch( url.approveChecklist, requestOptions );
310
318
 
311
-
319
+ console.log( searchResponse.ok );
312
320
  if ( searchResponse.ok ) {
313
321
  let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
314
- if ( pendingstores&&pendingstores.length>0 ) {
322
+ if ( pendingstores && pendingstores.length > 0 ) {
315
323
  return res.sendSuccess( `${pendingstores.length} remain pending approval due to being marked for redo.` );
316
324
  }
317
325
  return res.sendSuccess( 'Checklist has been approved the submitted stores' );
@@ -391,6 +399,7 @@ export async function redoChecklist( req, res ) {
391
399
  };
392
400
 
393
401
  let response = await processedChecklist.updateOne( { _id: req.body.payload._id }, updateData );
402
+ console.log( response );
394
403
  if ( response.modifiedCount || response.matchedCount ) {
395
404
  let storeTimeZone = await storeService.findOne( { storeName: checklistDetails.storeName }, { 'storeProfile.timeZone': 1 } );
396
405
  let currentDateTime;
@@ -407,8 +416,8 @@ export async function redoChecklist( req, res ) {
407
416
  sectionName: question[sectionIndex].sectionName,
408
417
  questionName: question[sectionIndex].questions[findQuestion].qname,
409
418
  action: 'redo',
410
- store_id: checklistDetails.store_id,
411
- storeName: checklistDetails.storeName,
419
+ store_id: checklistDetails?.store_id?checklistDetails?.store_id:'',
420
+ storeName: checklistDetails?.storeName?checklistDetails?.storeName:'',
412
421
  client_id: checklistDetails.client_id,
413
422
  processedChecklistId: checklistDetails._id,
414
423
  type: checklistDetails.checkListType,
@@ -419,8 +428,6 @@ export async function redoChecklist( req, res ) {
419
428
  submitedBy: checklistDetails.userName,
420
429
  submitTime: checklistDetails.submitTime,
421
430
  };
422
-
423
- // return;
424
431
  await checklistLogs.create( data );
425
432
 
426
433
  const requestOptions = {
@@ -432,7 +439,7 @@ export async function redoChecklist( req, res ) {
432
439
  };
433
440
  let url = JSON.parse( process.env.LAMBDAURL );
434
441
  let searchResponse = await fetch( url.redoChecklist, requestOptions );
435
-
442
+ console.log( searchResponse.ok );
436
443
 
437
444
  if ( searchResponse.ok ) {
438
445
  return res.sendSuccess( 'Question redo successfully' );
@@ -459,7 +466,7 @@ export async function getLogs( req, res ) {
459
466
  action: 'redo',
460
467
  } );
461
468
 
462
- let response =[];
469
+ let response = [];
463
470
  for ( let data of result ) {
464
471
  let userAnswer = {
465
472
  actionType: 'answer',
@@ -494,7 +501,7 @@ export async function approvalstatus( req, res ) {
494
501
  if ( Approver.length === 0 ) {
495
502
  return res.sendSuccess( 'suceess' );
496
503
  }
497
- let filterApprover = Approver.filter( ( data ) => data.userEmail=== req.user.email );
504
+ let filterApprover = Approver.filter( ( data ) => data.userEmail === req.user.email );
498
505
  if ( filterApprover.length === 0 ) {
499
506
  if ( ( req?.user?.userType == 'client' && req.user.role == 'superadmin' ) ) {
500
507
  let url = JSON.parse( process.env.LAMBDAURL );
@@ -538,9 +545,9 @@ export const headerStoresV2 = async ( req, res ) => {
538
545
  let totalStores = await getStoresList( getUserEmail, getClientId, getUserType, getRole, req );
539
546
 
540
547
 
541
- if ( totalStores && totalStores.length>0 ) {
548
+ if ( totalStores && totalStores.length > 0 ) {
542
549
  let storeQuery = [];
543
- if ( reqestData.city.length>0 && reqestData.clusters.length>0 ) {
550
+ if ( reqestData.city.length > 0 && reqestData.clusters.length > 0 ) {
544
551
  let unqueCityStores = await getLocationStores( getClientId, reqestData.city, req );
545
552
  let unqueGroupStores = await getClusterStores( getClientId, reqestData.clusters );
546
553
  storeQuery = [
@@ -561,7 +568,7 @@ export const headerStoresV2 = async ( req, res ) => {
561
568
  },
562
569
  },
563
570
  ];
564
- } else if ( reqestData.city.length>0 ) {
571
+ } else if ( reqestData.city.length > 0 ) {
565
572
  let uniqueCityStores = await getLocationStores( getClientId, reqestData.city, req );
566
573
  storeQuery = [
567
574
  {
@@ -580,7 +587,7 @@ export const headerStoresV2 = async ( req, res ) => {
580
587
  },
581
588
  },
582
589
  ];
583
- } else if ( reqestData.clusters.length>0 ) {
590
+ } else if ( reqestData.clusters.length > 0 ) {
584
591
  let uniqueclusterStores = await getClusterStores( getClientId, reqestData.clusters );
585
592
  storeQuery = [
586
593
  {
@@ -637,18 +644,18 @@ export const headerStoresV2 = async ( req, res ) => {
637
644
 
638
645
  async function getStoresList( getUserEmail, getClientId, getUserType, getRole, req ) {
639
646
  try {
640
- if ( getUserEmail && getUserEmail !='' && getClientId && getClientId !='' && getUserType && getUserType !='' && getRole && getRole!='' ) {
647
+ if ( getUserEmail && getUserEmail != '' && getClientId && getClientId != '' && getUserType && getUserType != '' && getRole && getRole != '' ) {
641
648
  let overAllStores = [];
642
649
  if ( getUserType == 'tango' ) {
643
650
  let getAllS = await getAssignedAllStores( getClientId );
644
- if ( getAllS && getAllS.length >0 ) {
651
+ if ( getAllS && getAllS.length > 0 ) {
645
652
  overAllStores = getAllS;
646
653
  }
647
654
  return overAllStores;
648
655
  } else if ( getUserType == 'client' ) {
649
656
  if ( getRole == 'superadmin' ) {
650
657
  let getAllS = await getAssignedAllStores( getClientId );
651
- if ( getAllS && getAllS.length >0 ) {
658
+ if ( getAllS && getAllS.length > 0 ) {
652
659
  overAllStores = getAllS;
653
660
  }
654
661
  return overAllStores;
@@ -667,7 +674,7 @@ async function getStoresList( getUserEmail, getClientId, getUserType, getRole, r
667
674
 
668
675
  async function getAssignedAllStores( userClientId ) {
669
676
  try {
670
- if ( userClientId && userClientId !='' ) {
677
+ if ( userClientId && userClientId != '' ) {
671
678
  let storeQuery = [
672
679
  {
673
680
  $match: {
@@ -684,7 +691,7 @@ async function getAssignedAllStores( userClientId ) {
684
691
  },
685
692
  ];
686
693
  const storeList = await storeService.aggregate( storeQuery );
687
- if ( storeList && storeList.length>0 && storeList[0]?.stores.length > 0 ) {
694
+ if ( storeList && storeList.length > 0 && storeList[0]?.stores.length > 0 ) {
688
695
  let uniqueStores = [ ...new Set( storeList[0].stores ) ];
689
696
  return uniqueStores;
690
697
  } else {
@@ -702,7 +709,7 @@ async function getAssignedAllStores( userClientId ) {
702
709
 
703
710
  async function getClusterStores( userClientId, ClusterList ) {
704
711
  try {
705
- if ( userClientId && userClientId !='' && ClusterList && ClusterList.length >0 ) {
712
+ if ( userClientId && userClientId != '' && ClusterList && ClusterList.length > 0 ) {
706
713
  let ClusterQuery = [
707
714
  {
708
715
  $match: {
@@ -736,7 +743,7 @@ async function getClusterStores( userClientId, ClusterList ) {
736
743
  },
737
744
  ];
738
745
  const clusterStoreList = await clusterService.aggregateCluster( ClusterQuery );
739
- if ( clusterStoreList && clusterStoreList.length>0 && clusterStoreList[0]?.storesList.length > 0 ) {
746
+ if ( clusterStoreList && clusterStoreList.length > 0 && clusterStoreList[0]?.storesList.length > 0 ) {
740
747
  let storeIds = clusterStoreList[0].storesList.map( ( data ) => data.storeId );
741
748
  let uniqueStores = [ ...new Set( storeIds ) ];
742
749
  return uniqueStores;
@@ -755,12 +762,12 @@ async function getClusterStores( userClientId, ClusterList ) {
755
762
 
756
763
  async function getLocationStores( userClientId, cityList, req ) {
757
764
  try {
758
- if ( userClientId && userClientId !='' && cityList && cityList.length >0 ) {
765
+ if ( userClientId && userClientId != '' && cityList && cityList.length > 0 ) {
759
766
  let filter = [
760
767
  { clientId: { $eq: userClientId } },
761
768
  { 'storeProfile.city': { $in: cityList } },
762
769
  ];
763
- if ( req.body.assignedStores&&req.body.assignedStores.length>0 ) {
770
+ if ( req.body.assignedStores && req.body.assignedStores.length > 0 ) {
764
771
  filter.push( { storeId: { $in: req.body.assignedStores } } );
765
772
  }
766
773
 
@@ -784,7 +791,7 @@ async function getLocationStores( userClientId, cityList, req ) {
784
791
  },
785
792
  ];
786
793
  const cityStoreList = await storeService.aggregate( storeQuery );
787
- if ( cityStoreList && cityStoreList.length>0 && cityStoreList[0]?.stores.length > 0 ) {
794
+ if ( cityStoreList && cityStoreList.length > 0 && cityStoreList[0]?.stores.length > 0 ) {
788
795
  let uniqueStores = [ ...new Set( cityStoreList[0].stores ) ];
789
796
  return uniqueStores;
790
797
  } else {
@@ -798,3 +805,89 @@ async function getLocationStores( userClientId, cityList, req ) {
798
805
  return false;
799
806
  }
800
807
  }
808
+
809
+ export async function teamsList( req, res ) {
810
+ try {
811
+ let query = [
812
+ {
813
+ $match: {
814
+ clientId: req.query.clientId,
815
+ },
816
+ },
817
+ ];
818
+
819
+
820
+ if ( req.user&&req.user.userType==='client'&&req.user.role!='superadmin' ) {
821
+ query.push( {
822
+ $match: {
823
+ Teamlead: {
824
+ $elemMatch: {
825
+ email: req.user.email,
826
+ },
827
+ },
828
+ },
829
+ } );
830
+ }
831
+ query.push( {
832
+ $project: {
833
+ teamName: 1,
834
+ clientId: 1,
835
+ },
836
+ } );
837
+ let teamList = await aggregateTeams( query );
838
+
839
+ res.sendSuccess( teamList );
840
+ } catch ( error ) {
841
+ logger.error( { error: error, function: 'teamsList' } );
842
+ return res.sendError( { error: error }, 500 );
843
+ }
844
+ }
845
+ export async function userList( req, res ) {
846
+ try {
847
+ let query = [
848
+ {
849
+ $match: {
850
+ clientId: req.body.clientId,
851
+ },
852
+ },
853
+ {
854
+ $project: {
855
+ userName: 1,
856
+ userEmail: '$email',
857
+ },
858
+ },
859
+ ];
860
+ if ( req.user&&req.user.userType==='client'&&req.user.role!='superadmin' ) {
861
+ let findTeams = await findteams( { Teamlead: {
862
+ $elemMatch: {
863
+ email: req.user.email,
864
+ },
865
+ }, clientId: req.body.clientId } );
866
+ req.body.teams = findTeams.map( ( data ) => data.teamName );
867
+ }
868
+
869
+ if ( req.body.teams && req.body.teams.length > 0 ) {
870
+ let userEmails = [];
871
+ let findTeams = await findteams( { teamName: { $in: req.body.teams }, clientId: req.body.clientId } );
872
+ for ( let team of findTeams ) {
873
+ for ( let lead of team.Teamlead ) {
874
+ userEmails.push( lead.email );
875
+ }
876
+ for ( let user of team.users ) {
877
+ userEmails.push( user.email );
878
+ }
879
+ }
880
+ query.push( {
881
+ $match: {
882
+ userEmail: { $in: userEmails },
883
+ },
884
+ } );
885
+ }
886
+
887
+ let userList = await aggregate( query );
888
+ res.sendSuccess( userList );
889
+ } catch ( error ) {
890
+ logger.error( { error: error, function: 'userList' } );
891
+ return res.sendError( { error: error }, 500 );
892
+ }
893
+ }