tango-app-api-trax 3.3.1-beta-29 → 3.3.1-beta-30

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-29",
3
+ "version": "3.3.1-beta-30",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.2.49",
29
+ "tango-api-schema": "^2.2.52",
30
30
  "tango-app-api-middleware": "^3.1.55",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
@@ -292,11 +292,13 @@ export async function approveChecklist( req, res ) {
292
292
  if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
293
293
  let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
294
294
 
295
+
295
296
  let params = {
296
297
  'payload': {
297
298
  sourceCheckList_id: req.body.sourceCheckList_id,
298
299
  fromDate: req.body.fromDate,
299
300
  toDate: req.body.toDate,
301
+ filtertype: req.body.filtertype,
300
302
  store_id: inputstores,
301
303
  },
302
304
  'upsert': {
@@ -314,7 +316,7 @@ export async function approveChecklist( req, res ) {
314
316
  let url = JSON.parse( process.env.LAMBDAURL );
315
317
  let searchResponse = await fetch( url.approveChecklist, requestOptions );
316
318
 
317
-
319
+ console.log( searchResponse.ok );
318
320
  if ( searchResponse.ok ) {
319
321
  let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
320
322
  if ( pendingstores && pendingstores.length > 0 ) {
@@ -1989,11 +1989,6 @@ export const validateUserv1 = async ( req, res ) => {
1989
1989
  return res.sendError( 'User already Exists', 400 );
1990
1990
  }
1991
1991
  }
1992
- // let userChunk =await chunkArray( users, 10 );
1993
-
1994
- await Promise.all( users.map( async ( chunk ) => {
1995
- await processUser( [ chunk ] );
1996
- } ) );
1997
1992
 
1998
1993
  let userEmailList = assignDetails.map( ( item ) => item.userEmail.toLowerCase() );
1999
1994
  let storeList = assignDetails.map( ( item ) => item.storeName.toLowerCase() );
@@ -2015,6 +2010,23 @@ export const validateUserv1 = async ( req, res ) => {
2015
2010
  },
2016
2011
  ];
2017
2012
 
2013
+ let emailCheckQuery = [
2014
+ {
2015
+ $project: {
2016
+ newEmail: { $toLower: '$email' },
2017
+ isActive: 1,
2018
+ clientId: 1,
2019
+ },
2020
+ },
2021
+ {
2022
+ $match: {
2023
+ newEmail: { $in: userEmailList },
2024
+ isActive: true,
2025
+ clientId: { $ne: req.body.clientId },
2026
+ },
2027
+ },
2028
+ ];
2029
+
2018
2030
  let storeQuery = [
2019
2031
  {
2020
2032
  $project: {
@@ -2032,9 +2044,10 @@ export const validateUserv1 = async ( req, res ) => {
2032
2044
  },
2033
2045
  ];
2034
2046
 
2035
- let [ userDetails, storeDetails ] = await Promise.all[
2047
+ let [ userDetails, storeDetails, existEmail ] = await Promise.all[
2036
2048
  await userService.aggregate( userQuery ),
2037
- await storeService.aggregate( storeQuery )
2049
+ await storeService.aggregate( storeQuery ),
2050
+ await userService.aggregate( emailCheckQuery )
2038
2051
  ];
2039
2052
 
2040
2053
  let existUSerEmail = userDetails.map( ( ele ) => ele.email );
@@ -2044,8 +2057,8 @@ export const validateUserv1 = async ( req, res ) => {
2044
2057
  let existsStore = storeDetails.map( ( ele ) => ele.storeName );
2045
2058
  storeDetails = storeList.filter( ( ele ) => !existsStore.includes( ele ) );
2046
2059
 
2047
- if ( userDetails.length || storeDetails.length ) {
2048
- return res.sendError( { validate: false, user: userDetails, store: storeDetails }, 400 );
2060
+ if ( userDetails.length || storeDetails.length || existEmail.length ) {
2061
+ return res.sendError( { validate: false, user: userDetails, store: storeDetails, existEmail }, 400 );
2049
2062
  }
2050
2063
  return res.sendSuccess( { validate: true } );
2051
2064
  } catch ( e ) {
@@ -2073,15 +2086,21 @@ export async function assignChecklistUser( req, res ) {
2073
2086
  };
2074
2087
  await createUser( userData );
2075
2088
  } ) );
2076
- let assignData = await Promise.all( assignDetails.map( async ( assign ) => {
2077
- assign.checklistId = inputBody.checklistId;
2089
+ let assignData = [];
2090
+ await Promise.all( assignDetails.map( async ( assign ) => {
2091
+ assign.checklistId = inputBody.taskId;
2078
2092
  assign.checkListName = checklistDetails.checkListName;
2079
2093
  assign.coverage = inputBody.coverage;
2080
2094
  assign.clientId = inputBody.clientId;
2081
2095
  assign.upload = inputBody.type;
2082
- return await assignUsers( assign );
2096
+ let uploadData = await assignUsers( assign );
2097
+ if ( Array.isArray( uploadData ) ) {
2098
+ assignData.push( ...uploadData );
2099
+ } else {
2100
+ assignData.push( uploadData );
2101
+ }
2083
2102
  } ) );
2084
- return res.sendSuccess( { idList: assignData.map( ( item ) => item.assignId ), assignData } );
2103
+ return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => item.assignId.toString() ) ) ], assignData } );
2085
2104
  } catch ( e ) {
2086
2105
  logger.error( { functionName: 'assignUser', error: e } );
2087
2106
  return res.sendError( e, 500 );
@@ -2882,82 +2901,8 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
2882
2901
  userName: store.spocDetails?.[0]?.name,
2883
2902
  mobileNumber: store.spocDetails?.[0]?.phone || '',
2884
2903
  email: store.spocDetails[0].email,
2885
- password: '5dqFKAJj29PsV6P+kL+3Dw==',
2886
- role: 'user',
2887
- userType: 'client',
2888
- rolespermission: [
2889
- {
2890
- featureName: 'Global',
2891
- modules: [
2892
- {
2893
- name: 'Store',
2894
- isAdd: false,
2895
- isEdit: false,
2896
-
2897
- },
2898
- {
2899
- name: 'User',
2900
- isAdd: false,
2901
- isEdit: false,
2902
-
2903
- },
2904
- {
2905
- name: 'Camera',
2906
- isAdd: false,
2907
- isEdit: false,
2908
-
2909
- },
2910
- {
2911
- name: 'Configuration',
2912
- isAdd: false,
2913
- isEdit: false,
2914
-
2915
- },
2916
- {
2917
- name: 'Subscription',
2918
- isAdd: false,
2919
- isEdit: false,
2920
-
2921
- },
2922
- {
2923
- name: 'Billing',
2924
- isAdd: false,
2925
- isEdit: false,
2926
-
2927
- },
2928
- ],
2929
- },
2930
- {
2931
- featurName: 'TangoEye',
2932
- modules: [
2933
- {
2934
- name: 'ZoneTag',
2935
- isAdd: false,
2936
- isEdit: false,
2937
-
2938
- },
2939
- ],
2940
- },
2941
- {
2942
- featurName: 'TangoTrax',
2943
- modules: [
2944
- {
2945
- name: 'checklist',
2946
- isAdd: false,
2947
- isEdit: false,
2948
-
2949
- },
2950
- {
2951
- name: 'Task',
2952
- isAdd: false,
2953
- isEdit: false,
2954
-
2955
- },
2956
- ],
2957
- },
2958
- ],
2959
2904
  };
2960
- userDetails = await userService.create( data );
2905
+ userDetails = await createUser( data );
2961
2906
  }
2962
2907
  let data = {
2963
2908
  store_id: store?.storeId,
@@ -3175,35 +3120,37 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
3175
3120
  }
3176
3121
  }
3177
3122
  }
3178
- delete element4._id;
3179
- delete element4.checkFlag;
3180
- delete element4.isdeleted;
3181
- delete element4.createdAt;
3182
- delete element4.updatedAt;
3183
- element4.checkListId = updatedchecklist._id;
3184
- element4.checkListName = getCLconfig.checkListName;
3185
- element4.checkListDescription = getCLconfig.checkListDescription;
3186
- element4.date_iso = new Date( date );
3187
- element4.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
3188
- element4.allowedOverTime = getCLconfig.allowedOverTime;
3189
- element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
3190
- element4.scheduleStartTime = getCLconfig.scheduleStartTime;
3191
- element4.scheduleStartTime_iso = startTimeIso.format();
3192
- element4.scheduleEndTime = getCLconfig.scheduleEndTime;
3193
- element4.scheduleEndTime_iso = endTimeIso.format();
3194
- element4.createdBy = new ObjectId( getCLconfig.createdBy );
3195
- element4.createdByName = getCLconfig.createdByName;
3196
- element4.sourceCheckList_id = getCLconfig._id;
3197
- element4.checkListType = getCLconfig.checkListType;
3198
- element4.storeCount = getCLconfig.storeCount;
3199
- element4.questionCount = getCLconfig.questionCount;
3200
- element4.publishDate = getCLconfig.publishDate;
3201
- element4.locationCount = getCLconfig.locationCount;
3202
- element4.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
3203
- element4.approvalEnable = getCLconfig.approver.length ? true : false;
3204
- element4.remainder = getCLconfig?.remainder || [];
3205
- element4.restrictAttendance = getCLconfig?.restrictAttendance;
3206
- assignUserList.push( { ...element4 } );
3123
+ if ( !userIdList.includes( element4._id ) ) {
3124
+ delete element4._id;
3125
+ delete element4.checkFlag;
3126
+ delete element4.isdeleted;
3127
+ delete element4.createdAt;
3128
+ delete element4.updatedAt;
3129
+ element4.checkListId = updatedchecklist._id;
3130
+ element4.checkListName = getCLconfig.checkListName;
3131
+ element4.checkListDescription = getCLconfig.checkListDescription;
3132
+ element4.date_iso = new Date( date );
3133
+ element4.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
3134
+ element4.allowedOverTime = getCLconfig.allowedOverTime;
3135
+ element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
3136
+ element4.scheduleStartTime = getCLconfig.scheduleStartTime;
3137
+ element4.scheduleStartTime_iso = startTimeIso.format();
3138
+ element4.scheduleEndTime = getCLconfig.scheduleEndTime;
3139
+ element4.scheduleEndTime_iso = endTimeIso.format();
3140
+ element4.createdBy = new ObjectId( getCLconfig.createdBy );
3141
+ element4.createdByName = getCLconfig.createdByName;
3142
+ element4.sourceCheckList_id = getCLconfig._id;
3143
+ element4.checkListType = getCLconfig.checkListType;
3144
+ element4.storeCount = getCLconfig.storeCount;
3145
+ element4.questionCount = getCLconfig.questionCount;
3146
+ element4.publishDate = getCLconfig.publishDate;
3147
+ element4.locationCount = getCLconfig.locationCount;
3148
+ element4.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
3149
+ element4.approvalEnable = getCLconfig.approver.length ? true : false;
3150
+ element4.remainder = getCLconfig?.remainder || [];
3151
+ element4.restrictAttendance = getCLconfig?.restrictAttendance;
3152
+ assignUserList.push( { ...element4 } );
3153
+ }
3207
3154
  } ) );
3208
3155
 
3209
3156
  if ( userIdList.length ) {
@@ -3606,15 +3553,46 @@ async function assignUsers( data ) {
3606
3553
  ];
3607
3554
  let clusterDetails = await clusterServices.aggregateCluster( query );
3608
3555
  if ( clusterDetails.length ) {
3609
- assignedData = {
3610
- checkFlag: true,
3611
- checkListId: data.checklistId,
3612
- checkListName: data.checkListName,
3613
- client_id: data?.clientId,
3614
- clusterName: clusterDetails?.[0]?.clusterName,
3615
- assignId: data?.id || clusterDetails?.[0]?._id,
3616
- coverage: 'store',
3617
- };
3556
+ if ( !data.upload ) {
3557
+ assignedData = {
3558
+ checkFlag: true,
3559
+ checkListId: data.checklistId,
3560
+ checkListName: data.checkListName,
3561
+ client_id: data?.clientId,
3562
+ clusterName: clusterDetails?.[0]?.clusterName,
3563
+ assignId: data?.id || clusterDetails?.[0]?._id,
3564
+ coverage: 'store',
3565
+ };
3566
+ } else {
3567
+ let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
3568
+ let storeDetails = await storeService.find( { _id: clusterList } );
3569
+ assignedData = await Promise.all( storeDetails.map( async ( store ) => {
3570
+ let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
3571
+ if ( !userDetails ) {
3572
+ let userData = {
3573
+ userName: store.spocDetails?.[0]?.name,
3574
+ email: store.spocDetails[0].email,
3575
+ mobileNumber: store.spocDetails?.[0]?.phone,
3576
+ clientId: data.clientId,
3577
+ };
3578
+ userDetails = await createUser( userData );
3579
+ }
3580
+ let userData = {
3581
+ userId: userDetails?._id,
3582
+ userName: userDetails?.userName,
3583
+ userEmail: userDetails?.email,
3584
+ userPhone: userDetails?.mobileNumber,
3585
+ checkFlag: true,
3586
+ checkListId: data.checklistId,
3587
+ checkListName: data.checkListName,
3588
+ client_id: data.clientId,
3589
+ assignId: data?.id || clusterDetails?.[0]?._id,
3590
+ coverage: 'store',
3591
+ teamName: clusterDetails?.[0]?.clusterName,
3592
+ };
3593
+ return userData;
3594
+ } ) );
3595
+ }
3618
3596
  }
3619
3597
  } else {
3620
3598
  let query = [
@@ -3676,17 +3654,38 @@ async function assignUsers( data ) {
3676
3654
  },
3677
3655
  },
3678
3656
  ];
3679
- let teamDetails = await teamsServices.aggregate( query );
3657
+ let teamDetails = await teamsServices.aggregateTeams( query );
3680
3658
  if ( teamDetails.length ) {
3681
- assignedData = {
3682
- checkFlag: true,
3683
- checkListId: data.checklistId,
3684
- checkListName: data.checkListName,
3685
- client_id: data.clientId,
3686
- teamName: teamDetails?.[0]?.teamName,
3687
- assignId: data?.id || teamDetails?.[0]?._id,
3688
- coverage: 'user',
3689
- };
3659
+ if ( !data.upload ) {
3660
+ assignedData = {
3661
+ checkFlag: true,
3662
+ checkListId: data.checklistId,
3663
+ checkListName: data.checkListName,
3664
+ client_id: data.clientId,
3665
+ teamName: teamDetails?.[0]?.teamName,
3666
+ assignId: data?.id || teamDetails?.[0]?._id,
3667
+ coverage: 'user',
3668
+ };
3669
+ } else {
3670
+ let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
3671
+ let userDetails = await userService.find( { _id: userIdList } );
3672
+ assignedData = userDetails.map( ( user ) => {
3673
+ let userData = {
3674
+ userId: user._id,
3675
+ userName: user.userName,
3676
+ userEmail: user.email,
3677
+ userPhone: user.mobileNumber,
3678
+ checkFlag: true,
3679
+ checkListId: data.checklistId,
3680
+ checkListName: data.checkListName,
3681
+ client_id: data.clientId,
3682
+ assignId: data?.id || teamDetails?.[0]?._id,
3683
+ coverage: 'user',
3684
+ teamName: teamDetails?.[0]?.teamName,
3685
+ };
3686
+ return userData;
3687
+ } );
3688
+ }
3690
3689
  }
3691
3690
  } else {
3692
3691
  let query = [
@@ -3756,9 +3755,10 @@ export async function checklistAssign( req, res ) {
3756
3755
  if ( req.body.coverage == 'store' ) {
3757
3756
  let clusterDetails = await clusterServices.findcluster( { _id: { $in: req.body.idList } }, { stores: 1, clusterName: 1 } );
3758
3757
  if ( clusterDetails.length ) {
3758
+ let clusterList = clusterDetails.map( ( item ) => item._id.toString() );
3759
3759
  idList = [
3760
3760
  ...clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) ),
3761
- ...clusterDetails.filter( ( ele ) => !req.body.idList.includes( ele._id.toString() ) ).map( ( ele ) => ele._id ),
3761
+ ...req.body.idList.filter( ( ele ) => !clusterList.includes( ele._id ) ),
3762
3762
  ];
3763
3763
  } else {
3764
3764
  idList = req.body.idList;
@@ -3792,9 +3792,10 @@ export async function checklistAssign( req, res ) {
3792
3792
  } else {
3793
3793
  let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
3794
3794
  if ( teamDetails.length ) {
3795
+ let teamList = teamDetails.map( ( item ) => item._id.toString() );
3795
3796
  idList = [
3796
3797
  ...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
3797
- ...teamDetails.filter( ( ele ) => !req.body.idList.includes( ele._id.toString() ) ).map( ( ele ) => ele._id ),
3798
+ ...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
3798
3799
  ];
3799
3800
  } else {
3800
3801
  idList = req.body.idList;