tango-app-api-trax 3.3.1-beta-28 → 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-28",
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 ) {
@@ -1492,6 +1492,7 @@ export const updateConfigurev1 =async ( req, res ) => {
1492
1492
  approver: inputBody?.checkListDetails?.approver.length ? inputBody?.checkListDetails?.approver.map( ( item ) => {
1493
1493
  return { name: item.name, value: item.value };
1494
1494
  } ) : [],
1495
+ storeCount: inputBody.checkListDetails?.assignedUsers?.length || 0,
1495
1496
  };
1496
1497
 
1497
1498
  if ( inputBody?.checkListDetails?.approver.length ) {
@@ -1578,14 +1579,11 @@ export const updateConfigurev1 =async ( req, res ) => {
1578
1579
  clientId: req.body.clientId,
1579
1580
  checkListName: checklistDetails.checkListName,
1580
1581
  checklistId: checklistDetails._id,
1581
- coverage: checklistDetails.coverage,
1582
+ coverage: inputBody?.checkListDetails.coverage,
1582
1583
  };
1583
1584
  await assignUsers( data );
1584
1585
  } ) );
1585
1586
  }
1586
- if ( inputBody.coverage ) {
1587
- await assignedService.deleteMany( { coverage: { $ne: inputBody.coverage } } );
1588
- }
1589
1587
  if ( inputBody.submitType == 'publish' ) {
1590
1588
  if ( inputBody.checkListDetails.checkListType == 'custom' ) {
1591
1589
  let currentDate = dayjs.utc().format();
@@ -1991,11 +1989,6 @@ export const validateUserv1 = async ( req, res ) => {
1991
1989
  return res.sendError( 'User already Exists', 400 );
1992
1990
  }
1993
1991
  }
1994
- // let userChunk =await chunkArray( users, 10 );
1995
-
1996
- await Promise.all( users.map( async ( chunk ) => {
1997
- await processUser( [ chunk ] );
1998
- } ) );
1999
1992
 
2000
1993
  let userEmailList = assignDetails.map( ( item ) => item.userEmail.toLowerCase() );
2001
1994
  let storeList = assignDetails.map( ( item ) => item.storeName.toLowerCase() );
@@ -2017,6 +2010,23 @@ export const validateUserv1 = async ( req, res ) => {
2017
2010
  },
2018
2011
  ];
2019
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
+
2020
2030
  let storeQuery = [
2021
2031
  {
2022
2032
  $project: {
@@ -2034,9 +2044,10 @@ export const validateUserv1 = async ( req, res ) => {
2034
2044
  },
2035
2045
  ];
2036
2046
 
2037
- let [ userDetails, storeDetails ] = await Promise.all[
2047
+ let [ userDetails, storeDetails, existEmail ] = await Promise.all[
2038
2048
  await userService.aggregate( userQuery ),
2039
- await storeService.aggregate( storeQuery )
2049
+ await storeService.aggregate( storeQuery ),
2050
+ await userService.aggregate( emailCheckQuery )
2040
2051
  ];
2041
2052
 
2042
2053
  let existUSerEmail = userDetails.map( ( ele ) => ele.email );
@@ -2046,8 +2057,8 @@ export const validateUserv1 = async ( req, res ) => {
2046
2057
  let existsStore = storeDetails.map( ( ele ) => ele.storeName );
2047
2058
  storeDetails = storeList.filter( ( ele ) => !existsStore.includes( ele ) );
2048
2059
 
2049
- if ( userDetails.length || storeDetails.length ) {
2050
- 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 );
2051
2062
  }
2052
2063
  return res.sendSuccess( { validate: true } );
2053
2064
  } catch ( e ) {
@@ -2065,9 +2076,6 @@ export async function assignChecklistUser( req, res ) {
2065
2076
  if ( !checklistDetails ) {
2066
2077
  return res.sendError( 'No data found', 204 );
2067
2078
  }
2068
- if ( inputBody.type == 'upload' ) {
2069
- await assignedService.deleteMany( { checkListId: inputBody.checklistId } );
2070
- }
2071
2079
  await Promise.all( newUsers.map( async ( user ) => {
2072
2080
  let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
2073
2081
  let userData = {
@@ -2078,15 +2086,21 @@ export async function assignChecklistUser( req, res ) {
2078
2086
  };
2079
2087
  await createUser( userData );
2080
2088
  } ) );
2081
- let assignData = await Promise.all( assignDetails.map( async ( assign ) => {
2082
- assign.checklistId = inputBody.checklistId;
2089
+ let assignData = [];
2090
+ await Promise.all( assignDetails.map( async ( assign ) => {
2091
+ assign.checklistId = inputBody.taskId;
2083
2092
  assign.checkListName = checklistDetails.checkListName;
2084
2093
  assign.coverage = inputBody.coverage;
2085
2094
  assign.clientId = inputBody.clientId;
2086
2095
  assign.upload = inputBody.type;
2087
- 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
+ }
2088
2102
  } ) );
2089
- return res.sendSuccess( { idList: assignData.map( ( item ) => item.assignId ), assignData } );
2103
+ return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => item.assignId.toString() ) ) ], assignData } );
2090
2104
  } catch ( e ) {
2091
2105
  logger.error( { functionName: 'assignUser', error: e } );
2092
2106
  return res.sendError( e, 500 );
@@ -2887,82 +2901,8 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
2887
2901
  userName: store.spocDetails?.[0]?.name,
2888
2902
  mobileNumber: store.spocDetails?.[0]?.phone || '',
2889
2903
  email: store.spocDetails[0].email,
2890
- password: '5dqFKAJj29PsV6P+kL+3Dw==',
2891
- role: 'user',
2892
- userType: 'client',
2893
- rolespermission: [
2894
- {
2895
- featureName: 'Global',
2896
- modules: [
2897
- {
2898
- name: 'Store',
2899
- isAdd: false,
2900
- isEdit: false,
2901
-
2902
- },
2903
- {
2904
- name: 'User',
2905
- isAdd: false,
2906
- isEdit: false,
2907
-
2908
- },
2909
- {
2910
- name: 'Camera',
2911
- isAdd: false,
2912
- isEdit: false,
2913
-
2914
- },
2915
- {
2916
- name: 'Configuration',
2917
- isAdd: false,
2918
- isEdit: false,
2919
-
2920
- },
2921
- {
2922
- name: 'Subscription',
2923
- isAdd: false,
2924
- isEdit: false,
2925
-
2926
- },
2927
- {
2928
- name: 'Billing',
2929
- isAdd: false,
2930
- isEdit: false,
2931
-
2932
- },
2933
- ],
2934
- },
2935
- {
2936
- featurName: 'TangoEye',
2937
- modules: [
2938
- {
2939
- name: 'ZoneTag',
2940
- isAdd: false,
2941
- isEdit: false,
2942
-
2943
- },
2944
- ],
2945
- },
2946
- {
2947
- featurName: 'TangoTrax',
2948
- modules: [
2949
- {
2950
- name: 'checklist',
2951
- isAdd: false,
2952
- isEdit: false,
2953
-
2954
- },
2955
- {
2956
- name: 'Task',
2957
- isAdd: false,
2958
- isEdit: false,
2959
-
2960
- },
2961
- ],
2962
- },
2963
- ],
2964
2904
  };
2965
- userDetails = await userService.create( data );
2905
+ userDetails = await createUser( data );
2966
2906
  }
2967
2907
  let data = {
2968
2908
  store_id: store?.storeId,
@@ -3180,35 +3120,37 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
3180
3120
  }
3181
3121
  }
3182
3122
  }
3183
- delete element4._id;
3184
- delete element4.checkFlag;
3185
- delete element4.isdeleted;
3186
- delete element4.createdAt;
3187
- delete element4.updatedAt;
3188
- element4.checkListId = updatedchecklist._id;
3189
- element4.checkListName = getCLconfig.checkListName;
3190
- element4.checkListDescription = getCLconfig.checkListDescription;
3191
- element4.date_iso = new Date( date );
3192
- element4.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
3193
- element4.allowedOverTime = getCLconfig.allowedOverTime;
3194
- element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
3195
- element4.scheduleStartTime = getCLconfig.scheduleStartTime;
3196
- element4.scheduleStartTime_iso = startTimeIso.format();
3197
- element4.scheduleEndTime = getCLconfig.scheduleEndTime;
3198
- element4.scheduleEndTime_iso = endTimeIso.format();
3199
- element4.createdBy = new ObjectId( getCLconfig.createdBy );
3200
- element4.createdByName = getCLconfig.createdByName;
3201
- element4.sourceCheckList_id = getCLconfig._id;
3202
- element4.checkListType = getCLconfig.checkListType;
3203
- element4.storeCount = getCLconfig.storeCount;
3204
- element4.questionCount = getCLconfig.questionCount;
3205
- element4.publishDate = getCLconfig.publishDate;
3206
- element4.locationCount = getCLconfig.locationCount;
3207
- element4.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
3208
- element4.approvalEnable = getCLconfig.approver.length ? true : false;
3209
- element4.remainder = getCLconfig?.remainder || [];
3210
- element4.restrictAttendance = getCLconfig?.restrictAttendance;
3211
- 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
+ }
3212
3154
  } ) );
3213
3155
 
3214
3156
  if ( userIdList.length ) {
@@ -3609,17 +3551,48 @@ async function assignUsers( data ) {
3609
3551
  },
3610
3552
  },
3611
3553
  ];
3612
- let clusterDetails = await clusterServices.aggregate( query );
3554
+ let clusterDetails = await clusterServices.aggregateCluster( query );
3613
3555
  if ( clusterDetails.length ) {
3614
- assignedData = {
3615
- checkFlag: true,
3616
- checkListId: data.checklistId,
3617
- checkListName: data.checkListName,
3618
- client_id: data?.clientId,
3619
- clusterName: clusterDetails?.[0]?.clusterName,
3620
- assignId: data?.id || clusterDetails?.[0]?._id,
3621
- coverage: 'store',
3622
- };
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
+ }
3623
3596
  }
3624
3597
  } else {
3625
3598
  let query = [
@@ -3681,17 +3654,38 @@ async function assignUsers( data ) {
3681
3654
  },
3682
3655
  },
3683
3656
  ];
3684
- let teamDetails = await teamsServices.aggregate( query );
3657
+ let teamDetails = await teamsServices.aggregateTeams( query );
3685
3658
  if ( teamDetails.length ) {
3686
- assignedData = {
3687
- checkFlag: true,
3688
- checkListId: data.checklistId,
3689
- checkListName: data.checkListName,
3690
- client_id: data.clientId,
3691
- teamName: teamDetails?.[0]?.teamName,
3692
- assignId: data?.id || teamDetails?.[0]?._id,
3693
- coverage: 'user',
3694
- };
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
+ }
3695
3689
  }
3696
3690
  } else {
3697
3691
  let query = [
@@ -3761,9 +3755,11 @@ export async function checklistAssign( req, res ) {
3761
3755
  if ( req.body.coverage == 'store' ) {
3762
3756
  let clusterDetails = await clusterServices.findcluster( { _id: { $in: req.body.idList } }, { stores: 1, clusterName: 1 } );
3763
3757
  if ( clusterDetails.length ) {
3764
- idList = clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) );
3765
- let storeList = clusterDetails.filter( ( ele ) => !req.body.idList.includes( ele._id.toString() ) ).map( ( ele ) => ele._id );
3766
- idList = [ ...idList, ...storeList ];
3758
+ let clusterList = clusterDetails.map( ( item ) => item._id.toString() );
3759
+ idList = [
3760
+ ...clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) ),
3761
+ ...req.body.idList.filter( ( ele ) => !clusterList.includes( ele._id ) ),
3762
+ ];
3767
3763
  } else {
3768
3764
  idList = req.body.idList;
3769
3765
  }
@@ -3796,9 +3792,11 @@ export async function checklistAssign( req, res ) {
3796
3792
  } else {
3797
3793
  let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
3798
3794
  if ( teamDetails.length ) {
3799
- idList = teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) );
3800
- let userList = teamDetails.filter( ( ele ) => !req.body.idList.includes( ele._id.toString() ) );
3801
- idList = [ ...idList, ...userList ];
3795
+ let teamList = teamDetails.map( ( item ) => item._id.toString() );
3796
+ idList = [
3797
+ ...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
3798
+ ...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
3799
+ ];
3802
3800
  } else {
3803
3801
  idList = req.body.idList;
3804
3802
  }
@@ -3824,39 +3822,3 @@ export async function checklistAssign( req, res ) {
3824
3822
  }
3825
3823
  }
3826
3824
 
3827
- // export async function removeAssign( req, res ) {
3828
- // try {
3829
- // if ( !req.body.id ) {
3830
- // return res.sendError( 'Id is required', 400 );
3831
- // }
3832
- // if ( !req.body.checkListId ) {
3833
- // return res.sendError( 'Checklist id is required', 400 );
3834
- // }
3835
- // let checklistDetails = await checklistService.findOne( { _id: req.body.checkListId } );
3836
- // if ( !checklistDetails ) {
3837
- // return res.sendError( 'No data found', 204 );
3838
- // }
3839
- // await assignedService.deleteMany( { assignId: { $in: req.body.id } } );
3840
- // return res.sendSuccess( 'Details removed successfully' );
3841
- // } catch ( e ) {
3842
- // logger.error( { functionName: 'removeAssign', error: e } );
3843
- // return res.sendError( e, 500 );
3844
- // }
3845
- // }
3846
-
3847
- // export async function deleteAssignList( req, res ) {
3848
- // try {
3849
- // if ( !req.body.checkListId ) {
3850
- // return res.sendError( 'Checklist id is required', 400 );
3851
- // }
3852
- // let checklistDetails = await checklistService.findOne( { _id: req.body.checkListId, isdeleted: false } );
3853
- // if ( !checklistDetails ) {
3854
- // return res.sendError( 'No data found', 204 );
3855
- // }
3856
- // await assignedService.updateMany( { checkListId: req.body.checkListId }, { isdeleted: true } );
3857
- // return res.sendSuccess( 'Assign details removed successfully' );
3858
- // } catch ( e ) {
3859
- // logger.error( { functionName: 'deleteAssignList', error: e } );
3860
- // return res.sendError( e, 500 );
3861
- // }
3862
- // }