tango-app-api-trax 3.3.1-beta-12 → 3.3.1-beta-14

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-12",
3
+ "version": "3.3.1-beta-14",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -900,7 +900,7 @@ export const assignedUserDetails = async ( req, res ) => {
900
900
  userDetails.push( {
901
901
  id: ele._id,
902
902
  userName: item.spocDetails?.[0]?.name,
903
- userEmail: item.spocDetails[0].email,
903
+ userEmail: item.spocDetails?.[0]?.email,
904
904
  store_id: item?.storeId,
905
905
  storeName: item?.storeName,
906
906
  userPhone: item.spocDetails?.[0]?.phone,
@@ -945,9 +945,16 @@ export const assignedUserDetails = async ( req, res ) => {
945
945
  } );
946
946
  }
947
947
  } ) );
948
-
949
- userDetails.sort( ( a, b ) => b.teamName - a.teamName );
950
- console.log( userDetails );
948
+ if ( req.query.sortColumn && req.query.sortBy ) {
949
+ const sortColumn = req.query.sortColumn;
950
+ const sortBy = parseInt( req.query.sortBy, 10 ) === -1 ? -1 : 1;
951
+ userDetails.sort( ( a, b ) => {
952
+ if ( a[sortColumn] == null || b[sortColumn] == null ) return 0;
953
+ if ( typeof a[sortColumn] === 'string' && typeof b[sortColumn] === 'string' ) {
954
+ return sortBy * a[sortColumn].localeCompare( b[sortColumn] );
955
+ }
956
+ } );
957
+ }
951
958
  let limitedData = userDetails.slice( skip, limit + skip );
952
959
  return res.sendSuccess( { count: userDetails.length, storeList, userList, users: limitedData } );
953
960
  } catch ( e ) {
@@ -1476,6 +1483,9 @@ export const updateConfigurev1 =async ( req, res ) => {
1476
1483
  // await assignUsers( data );
1477
1484
  // } ) );
1478
1485
  // }
1486
+ if ( inputBody.coverage ) {
1487
+ await assignedService.deleteMany( { coverage: { $ne: inputBody.coverage } } );
1488
+ }
1479
1489
  if ( inputBody.submitType == 'publish' ) {
1480
1490
  if ( inputBody.checkListDetails.checkListType == 'custom' ) {
1481
1491
  let currentDate = dayjs.utc().format();
@@ -1947,15 +1957,35 @@ export const validateUserv1 = async ( req, res ) => {
1947
1957
  }
1948
1958
  };
1949
1959
 
1950
- export async function assignUser( req, res ) {
1960
+ export async function assignChecklistUser( req, res ) {
1951
1961
  try {
1952
1962
  let inputBody = req.body;
1953
1963
  let assignDetails = inputBody.assignUsers;
1964
+ let newUsers = inputBody.newUsers;
1954
1965
  if ( inputBody.type == 'upload' ) {
1955
1966
  await assignedService.deleteMany( { checkListId: inputBody.checklistId } );
1956
1967
  }
1957
- await Promise.all( assignDetails.map( ( assign ) => {
1958
- assignUsers( assign );
1968
+ let checklistDetails = await checklistService.findOne( { _id: inputBody.checklistId } );
1969
+ if ( !checklistDetails ) {
1970
+ return res.sendError( 'No data found', 204 );
1971
+ }
1972
+ await Promise.all( newUsers.map( async ( user ) => {
1973
+ let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
1974
+ let userData = {
1975
+ userName: getUser.userName,
1976
+ email: user,
1977
+ mobileNumber: getUser?.phone,
1978
+ clientId: inputBody.clientId,
1979
+ };
1980
+ await createUser( userData );
1981
+ } ) );
1982
+ await Promise.all( assignDetails.map( async ( assign ) => {
1983
+ assign.checklistId = inputBody.checklistId;
1984
+ assign.checkListName = checklistDetails.checkListName;
1985
+ assign.coverage = inputBody.coverage;
1986
+ assign.clientId = inputBody.clientId;
1987
+ assign.upload = inputBody.type;
1988
+ await assignUsers( assign );
1959
1989
  } ) );
1960
1990
  return res.sendSuccess( 'Details updated successfully' );
1961
1991
  } catch ( e ) {
@@ -2998,8 +3028,9 @@ export const selectAssign = async ( req, res ) => {
2998
3028
  async function assignUsers( data ) {
2999
3029
  let assignedData;
3000
3030
  if ( data.coverage == 'store' ) {
3001
- if ( data.type == 'cluster' ) {
3002
- let clusterDetails = await clusterServices.findOneCluster( { _id: data.id }, { stores: 1, clusterName: 1 } );
3031
+ if ( data?.type == 'cluster' ) {
3032
+ let query = !data?.upload ? { _id: data.id } : { clusterName: data.clusterName, clientId: data.clientId };
3033
+ let clusterDetails = await clusterServices.findOneCluster( query, { stores: 1, clusterName: 1 } );
3003
3034
  if ( clusterDetails ) {
3004
3035
  assignedData = {
3005
3036
  checkFlag: true,
@@ -3007,13 +3038,16 @@ async function assignUsers( data ) {
3007
3038
  checkListName: data.checkListName,
3008
3039
  client_id: data?.clientId,
3009
3040
  clusterName: clusterDetails?.clusterName,
3010
- assignId: data.id,
3041
+ assignId: data?.id || clusterDetails?._id,
3042
+ coverage: 'store',
3011
3043
  };
3012
3044
  }
3013
3045
  } else {
3014
- let storeDetails = await storeService.findOne( { _id: data.id } );
3046
+ let query = !data?.upload ? { _id: data.id } : { storeName: data.storeName };
3047
+ let storeDetails = await storeService.findOne( query );
3015
3048
  if ( storeDetails ) {
3016
- let userDetails = await userService.findOne( { userEmail: storeDetails?.spocDetails?.email, clientId: data.clientId } );
3049
+ let email = data?.upload ? data.userEmail : storeDetails?.spocDetails?.email;
3050
+ let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
3017
3051
  if ( !userDetails ) {
3018
3052
  let userData = {
3019
3053
  userName: storeDetails.spocDetails?.[0]?.name,
@@ -3021,7 +3055,7 @@ async function assignUsers( data ) {
3021
3055
  mobileNumber: storeDetails.spocDetails?.[0]?.phone,
3022
3056
  clientId: data.clientId,
3023
3057
  };
3024
- createUser( userData );
3058
+ userDetails = createUser( userData );
3025
3059
  }
3026
3060
  assignedData = {
3027
3061
  store_id: storeDetails.storeId,
@@ -3031,18 +3065,20 @@ async function assignUsers( data ) {
3031
3065
  userEmail: userDetails.email,
3032
3066
  userPhone: userDetails?.mobileNumber,
3033
3067
  city: storeDetails?.storeProfile?.city,
3034
- country: storeDetails?.storeprofile?.country,
3068
+ country: storeDetails?.storeProfile?.country,
3035
3069
  checkFlag: true,
3036
3070
  checkListId: data.checklistId,
3037
3071
  checkListName: data.checkListName,
3038
3072
  client_id: data.clientId,
3039
- assignId: data.id,
3073
+ assignId: data?.id || storeDetails._id,
3074
+ coverage: 'store',
3040
3075
  };
3041
3076
  }
3042
3077
  }
3043
3078
  } else {
3044
3079
  if ( data.type == 'teams' ) {
3045
- let teamDetails = await teamsServices.findOneTeams( { _id: data.id }, { users: 1, teamName: 1 } );
3080
+ let query = !data?.upload ? { _id: data.id } : { teamName: data.teamName, clientId: data.clientId };
3081
+ let teamDetails = await teamsServices.findOneTeams( query, { users: 1, teamName: 1 } );
3046
3082
  if ( teamDetails ) {
3047
3083
  assignedData = {
3048
3084
  checkFlag: true,
@@ -3050,11 +3086,13 @@ async function assignUsers( data ) {
3050
3086
  checkListName: data.checkListName,
3051
3087
  client_id: data.clientId,
3052
3088
  teamName: teamDetails?.teamName,
3053
- assignId: data.id,
3089
+ assignId: data?.id || teamDetails?._id,
3090
+ coverage: 'user',
3054
3091
  };
3055
3092
  }
3056
3093
  } else {
3057
- let userDetails = await userService.findOne( { _id: { $in: data.id } } );
3094
+ let query = !data?.upload ? { _id: data.id } : { email: data.email, clientId: data.clientId };
3095
+ let userDetails = await userService.findOne( query );
3058
3096
  if ( userDetails ) {
3059
3097
  assignedData = {
3060
3098
  userId: userDetails._id,
@@ -3065,24 +3103,24 @@ async function assignUsers( data ) {
3065
3103
  checkListId: data.checklistId,
3066
3104
  checkListName: data.checkListName,
3067
3105
  client_id: data.clientId,
3068
- assignId: data.id,
3106
+ assignId: data?.id || userDetails?._id,
3107
+ coverage: 'user',
3069
3108
  };
3070
3109
  }
3071
3110
  }
3072
3111
  }
3073
- await assignedService.create( assignedData );
3112
+ if ( assignedData ) {
3113
+ await assignedService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
3114
+ }
3074
3115
  }
3075
3116
 
3076
3117
  export async function checklistAssign( req, res ) {
3077
3118
  try {
3078
- if ( !req.body.type ) {
3079
- return res.sendError( 'Type is required', 400 );
3080
- }
3081
3119
  if ( !req.body.coverage ) {
3082
3120
  return res.sendError( 'coverage is required', 400 );
3083
3121
  }
3084
- if ( !req.body.id ) {
3085
- return res.sendError( 'coverage is required', 400 );
3122
+ if ( !req.body.idList ) {
3123
+ return res.sendError( 'Id list is required', 400 );
3086
3124
  }
3087
3125
  if ( !req.body.checklistId ) {
3088
3126
  return res.sendError( 'Checklist id is required', 400 );
@@ -3095,7 +3133,10 @@ export async function checklistAssign( req, res ) {
3095
3133
  return res.sendError( 'No data found', 204 );
3096
3134
  }
3097
3135
  req.body.checkListName = checklistDetails.checkListName;
3098
- await assignUsers( req.body );
3136
+ await Promise.all( req.body.idList.map( async ( ele ) => {
3137
+ let storeData = { ...req.body, type: ele.type, id: ele.id };
3138
+ await assignUsers( storeData );
3139
+ } ) );
3099
3140
  return res.sendSuccess( 'Details updated successfully' );
3100
3141
  } catch ( e ) {
3101
3142
  logger.error( { functionName: 'checklistAssign', error: e } );
@@ -3103,25 +3144,25 @@ export async function checklistAssign( req, res ) {
3103
3144
  }
3104
3145
  }
3105
3146
 
3106
- export async function removeAssign( req, res ) {
3107
- try {
3108
- if ( !req.body.id ) {
3109
- return res.sendError( 'Id is required', 400 );
3110
- }
3111
- if ( !req.body.checkListId ) {
3112
- return res.sendError( 'Checklist id is required', 400 );
3113
- }
3114
- let checklistDetails = await checklistService.findOne( { _id: req.body.checkListId } );
3115
- if ( !checklistDetails ) {
3116
- return res.sendError( 'No data found', 204 );
3117
- }
3118
- await assignedService.deleteMany( { assignId: req.body.id } );
3119
- return res.sendSuccess( 'Details removed successfully' );
3120
- } catch ( e ) {
3121
- logger.error( { functionName: 'removeAssign', error: e } );
3122
- return res.sendError( e, 500 );
3123
- }
3124
- }
3147
+ // export async function removeAssign( req, res ) {
3148
+ // try {
3149
+ // if ( !req.body.id ) {
3150
+ // return res.sendError( 'Id is required', 400 );
3151
+ // }
3152
+ // if ( !req.body.checkListId ) {
3153
+ // return res.sendError( 'Checklist id is required', 400 );
3154
+ // }
3155
+ // let checklistDetails = await checklistService.findOne( { _id: req.body.checkListId } );
3156
+ // if ( !checklistDetails ) {
3157
+ // return res.sendError( 'No data found', 204 );
3158
+ // }
3159
+ // await assignedService.updateMany( { assignId: { $in: req.body.id } }, { isdeleted: true } );
3160
+ // return res.sendSuccess( 'Details removed successfully' );
3161
+ // } catch ( e ) {
3162
+ // logger.error( { functionName: 'removeAssign', error: e } );
3163
+ // return res.sendError( e, 500 );
3164
+ // }
3165
+ // }
3125
3166
 
3126
3167
  export async function deleteAssignList( req, res ) {
3127
3168
  try {