tango-app-api-trax 3.3.1-beta-17 → 3.3.1-beta-19

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.3.1-beta-17",
3
+ "version": "3.3.1-beta-19",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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,6 +141,8 @@ export const downloadInsert = async ( req, res ) => {
121
141
  'searchValue': requestData.searchValue || '',
122
142
  'insertType': requestData.insertType || '',
123
143
  'viewRedo': requestData.viewRedo || false,
144
+ 'userEmailList': requestData.userEmailList || [],
145
+ 'filtertype': requestData.filtertype || 'Clusters',
124
146
 
125
147
  };
126
148
  let resultData = await downloadService.insert( insertData );
@@ -418,6 +440,8 @@ export const getChecklistFromZipId = async ( req, res ) => {
418
440
  resultData.storeIds = getzipdata.storeIds;
419
441
  resultData.questions = getzipdata.questions;
420
442
  resultData.fileType = getzipdata.fileType;
443
+ resultData.userEmailList = getzipdata.userEmailList;
444
+ resultData.filtertype = getzipdata.filtertype;
421
445
  resultData.viewFlag = getzipdata.viewFlag;
422
446
  resultData.previewType = getzipdata.previewType || '';
423
447
  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 } );
@@ -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,7 +291,7 @@ 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
+
289
295
  let params = {
290
296
  'payload': {
291
297
  sourceCheckList_id: req.body.sourceCheckList_id,
@@ -311,7 +317,7 @@ export async function approveChecklist( req, res ) {
311
317
 
312
318
  if ( searchResponse.ok ) {
313
319
  let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
314
- if ( pendingstores&&pendingstores.length>0 ) {
320
+ if ( pendingstores && pendingstores.length > 0 ) {
315
321
  return res.sendSuccess( `${pendingstores.length} remain pending approval due to being marked for redo.` );
316
322
  }
317
323
  return res.sendSuccess( 'Checklist has been approved the submitted stores' );
@@ -459,7 +465,7 @@ export async function getLogs( req, res ) {
459
465
  action: 'redo',
460
466
  } );
461
467
 
462
- let response =[];
468
+ let response = [];
463
469
  for ( let data of result ) {
464
470
  let userAnswer = {
465
471
  actionType: 'answer',
@@ -494,7 +500,7 @@ export async function approvalstatus( req, res ) {
494
500
  if ( Approver.length === 0 ) {
495
501
  return res.sendSuccess( 'suceess' );
496
502
  }
497
- let filterApprover = Approver.filter( ( data ) => data.userEmail=== req.user.email );
503
+ let filterApprover = Approver.filter( ( data ) => data.userEmail === req.user.email );
498
504
  if ( filterApprover.length === 0 ) {
499
505
  if ( ( req?.user?.userType == 'client' && req.user.role == 'superadmin' ) ) {
500
506
  let url = JSON.parse( process.env.LAMBDAURL );
@@ -538,9 +544,9 @@ export const headerStoresV2 = async ( req, res ) => {
538
544
  let totalStores = await getStoresList( getUserEmail, getClientId, getUserType, getRole, req );
539
545
 
540
546
 
541
- if ( totalStores && totalStores.length>0 ) {
547
+ if ( totalStores && totalStores.length > 0 ) {
542
548
  let storeQuery = [];
543
- if ( reqestData.city.length>0 && reqestData.clusters.length>0 ) {
549
+ if ( reqestData.city.length > 0 && reqestData.clusters.length > 0 ) {
544
550
  let unqueCityStores = await getLocationStores( getClientId, reqestData.city, req );
545
551
  let unqueGroupStores = await getClusterStores( getClientId, reqestData.clusters );
546
552
  storeQuery = [
@@ -561,7 +567,7 @@ export const headerStoresV2 = async ( req, res ) => {
561
567
  },
562
568
  },
563
569
  ];
564
- } else if ( reqestData.city.length>0 ) {
570
+ } else if ( reqestData.city.length > 0 ) {
565
571
  let uniqueCityStores = await getLocationStores( getClientId, reqestData.city, req );
566
572
  storeQuery = [
567
573
  {
@@ -580,7 +586,7 @@ export const headerStoresV2 = async ( req, res ) => {
580
586
  },
581
587
  },
582
588
  ];
583
- } else if ( reqestData.clusters.length>0 ) {
589
+ } else if ( reqestData.clusters.length > 0 ) {
584
590
  let uniqueclusterStores = await getClusterStores( getClientId, reqestData.clusters );
585
591
  storeQuery = [
586
592
  {
@@ -637,18 +643,18 @@ export const headerStoresV2 = async ( req, res ) => {
637
643
 
638
644
  async function getStoresList( getUserEmail, getClientId, getUserType, getRole, req ) {
639
645
  try {
640
- if ( getUserEmail && getUserEmail !='' && getClientId && getClientId !='' && getUserType && getUserType !='' && getRole && getRole!='' ) {
646
+ if ( getUserEmail && getUserEmail != '' && getClientId && getClientId != '' && getUserType && getUserType != '' && getRole && getRole != '' ) {
641
647
  let overAllStores = [];
642
648
  if ( getUserType == 'tango' ) {
643
649
  let getAllS = await getAssignedAllStores( getClientId );
644
- if ( getAllS && getAllS.length >0 ) {
650
+ if ( getAllS && getAllS.length > 0 ) {
645
651
  overAllStores = getAllS;
646
652
  }
647
653
  return overAllStores;
648
654
  } else if ( getUserType == 'client' ) {
649
655
  if ( getRole == 'superadmin' ) {
650
656
  let getAllS = await getAssignedAllStores( getClientId );
651
- if ( getAllS && getAllS.length >0 ) {
657
+ if ( getAllS && getAllS.length > 0 ) {
652
658
  overAllStores = getAllS;
653
659
  }
654
660
  return overAllStores;
@@ -667,7 +673,7 @@ async function getStoresList( getUserEmail, getClientId, getUserType, getRole, r
667
673
 
668
674
  async function getAssignedAllStores( userClientId ) {
669
675
  try {
670
- if ( userClientId && userClientId !='' ) {
676
+ if ( userClientId && userClientId != '' ) {
671
677
  let storeQuery = [
672
678
  {
673
679
  $match: {
@@ -684,7 +690,7 @@ async function getAssignedAllStores( userClientId ) {
684
690
  },
685
691
  ];
686
692
  const storeList = await storeService.aggregate( storeQuery );
687
- if ( storeList && storeList.length>0 && storeList[0]?.stores.length > 0 ) {
693
+ if ( storeList && storeList.length > 0 && storeList[0]?.stores.length > 0 ) {
688
694
  let uniqueStores = [ ...new Set( storeList[0].stores ) ];
689
695
  return uniqueStores;
690
696
  } else {
@@ -702,7 +708,7 @@ async function getAssignedAllStores( userClientId ) {
702
708
 
703
709
  async function getClusterStores( userClientId, ClusterList ) {
704
710
  try {
705
- if ( userClientId && userClientId !='' && ClusterList && ClusterList.length >0 ) {
711
+ if ( userClientId && userClientId != '' && ClusterList && ClusterList.length > 0 ) {
706
712
  let ClusterQuery = [
707
713
  {
708
714
  $match: {
@@ -736,7 +742,7 @@ async function getClusterStores( userClientId, ClusterList ) {
736
742
  },
737
743
  ];
738
744
  const clusterStoreList = await clusterService.aggregateCluster( ClusterQuery );
739
- if ( clusterStoreList && clusterStoreList.length>0 && clusterStoreList[0]?.storesList.length > 0 ) {
745
+ if ( clusterStoreList && clusterStoreList.length > 0 && clusterStoreList[0]?.storesList.length > 0 ) {
740
746
  let storeIds = clusterStoreList[0].storesList.map( ( data ) => data.storeId );
741
747
  let uniqueStores = [ ...new Set( storeIds ) ];
742
748
  return uniqueStores;
@@ -755,12 +761,12 @@ async function getClusterStores( userClientId, ClusterList ) {
755
761
 
756
762
  async function getLocationStores( userClientId, cityList, req ) {
757
763
  try {
758
- if ( userClientId && userClientId !='' && cityList && cityList.length >0 ) {
764
+ if ( userClientId && userClientId != '' && cityList && cityList.length > 0 ) {
759
765
  let filter = [
760
766
  { clientId: { $eq: userClientId } },
761
767
  { 'storeProfile.city': { $in: cityList } },
762
768
  ];
763
- if ( req.body.assignedStores&&req.body.assignedStores.length>0 ) {
769
+ if ( req.body.assignedStores && req.body.assignedStores.length > 0 ) {
764
770
  filter.push( { storeId: { $in: req.body.assignedStores } } );
765
771
  }
766
772
 
@@ -784,7 +790,7 @@ async function getLocationStores( userClientId, cityList, req ) {
784
790
  },
785
791
  ];
786
792
  const cityStoreList = await storeService.aggregate( storeQuery );
787
- if ( cityStoreList && cityStoreList.length>0 && cityStoreList[0]?.stores.length > 0 ) {
793
+ if ( cityStoreList && cityStoreList.length > 0 && cityStoreList[0]?.stores.length > 0 ) {
788
794
  let uniqueStores = [ ...new Set( cityStoreList[0].stores ) ];
789
795
  return uniqueStores;
790
796
  } else {
@@ -798,3 +804,89 @@ async function getLocationStores( userClientId, cityList, req ) {
798
804
  return false;
799
805
  }
800
806
  }
807
+
808
+ export async function teamsList( req, res ) {
809
+ try {
810
+ let query = [
811
+ {
812
+ $match: {
813
+ clientId: req.query.clientId,
814
+ },
815
+ },
816
+ ];
817
+
818
+
819
+ if ( req.user&&req.user.userType==='client'&&req.user.role!='superadmin' ) {
820
+ query.push( {
821
+ $match: {
822
+ Teamlead: {
823
+ $elemMatch: {
824
+ email: req.user.email,
825
+ },
826
+ },
827
+ },
828
+ } );
829
+ }
830
+ query.push( {
831
+ $project: {
832
+ teamName: 1,
833
+ clientId: 1,
834
+ },
835
+ } );
836
+ let teamList = await aggregateTeams( query );
837
+
838
+ res.sendSuccess( teamList );
839
+ } catch ( error ) {
840
+ logger.error( { error: error, function: 'teamsList' } );
841
+ return res.sendError( { error: error }, 500 );
842
+ }
843
+ }
844
+ export async function userList( req, res ) {
845
+ try {
846
+ let query = [
847
+ {
848
+ $match: {
849
+ clientId: req.body.clientId,
850
+ },
851
+ },
852
+ {
853
+ $project: {
854
+ userName: 1,
855
+ userEmail: '$email',
856
+ },
857
+ },
858
+ ];
859
+ if ( req.user&&req.user.userType==='client'&&req.user.role!='superadmin' ) {
860
+ let findTeams = await findteams( { Teamlead: {
861
+ $elemMatch: {
862
+ email: req.user.email,
863
+ },
864
+ }, clientId: req.body.clientId } );
865
+ req.body.teams = findTeams.map( ( data ) => data.teamName );
866
+ }
867
+
868
+ if ( req.body.teams && req.body.teams.length > 0 ) {
869
+ let userEmails = [];
870
+ let findTeams = await findteams( { teamName: { $in: req.body.teams }, clientId: req.body.clientId } );
871
+ for ( let team of findTeams ) {
872
+ for ( let lead of team.Teamlead ) {
873
+ userEmails.push( lead.email );
874
+ }
875
+ for ( let user of team.users ) {
876
+ userEmails.push( user.email );
877
+ }
878
+ }
879
+ query.push( {
880
+ $match: {
881
+ userEmail: { $in: userEmails },
882
+ },
883
+ } );
884
+ }
885
+
886
+ let userList = await aggregate( query );
887
+ res.sendSuccess( userList );
888
+ } catch ( error ) {
889
+ logger.error( { error: error, function: 'userList' } );
890
+ return res.sendError( { error: error }, 500 );
891
+ }
892
+ }