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

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-13",
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 ) {
@@ -1947,15 +1954,35 @@ export const validateUserv1 = async ( req, res ) => {
1947
1954
  }
1948
1955
  };
1949
1956
 
1950
- export async function assignUser( req, res ) {
1957
+ export async function assignChecklistUser( req, res ) {
1951
1958
  try {
1952
1959
  let inputBody = req.body;
1953
1960
  let assignDetails = inputBody.assignUsers;
1961
+ let newUsers = inputBody.newUsers;
1954
1962
  if ( inputBody.type == 'upload' ) {
1955
1963
  await assignedService.deleteMany( { checkListId: inputBody.checklistId } );
1956
1964
  }
1957
- await Promise.all( assignDetails.map( ( assign ) => {
1958
- assignUsers( assign );
1965
+ let checklistDetails = await checklistService.findOne( { _id: inputBody.checklistId } );
1966
+ if ( !checklistDetails ) {
1967
+ return res.sendError( 'No data found', 204 );
1968
+ }
1969
+ await Promise.all( newUsers.map( async ( user ) => {
1970
+ let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
1971
+ let userData = {
1972
+ userName: getUser.userName,
1973
+ email: user,
1974
+ mobileNumber: getUser?.phone,
1975
+ clientId: inputBody.clientId,
1976
+ };
1977
+ await createUser( userData );
1978
+ } ) );
1979
+ await Promise.all( assignDetails.map( async ( assign ) => {
1980
+ assign.checklistId = inputBody.checklistId;
1981
+ assign.checkListName = checklistDetails.checkListName;
1982
+ assign.coverage = inputBody.coverage;
1983
+ assign.clientId = inputBody.clientId;
1984
+ assign.upload = inputBody.type;
1985
+ await assignUsers( assign );
1959
1986
  } ) );
1960
1987
  return res.sendSuccess( 'Details updated successfully' );
1961
1988
  } catch ( e ) {
@@ -2998,8 +3025,9 @@ export const selectAssign = async ( req, res ) => {
2998
3025
  async function assignUsers( data ) {
2999
3026
  let assignedData;
3000
3027
  if ( data.coverage == 'store' ) {
3001
- if ( data.type == 'cluster' ) {
3002
- let clusterDetails = await clusterServices.findOneCluster( { _id: data.id }, { stores: 1, clusterName: 1 } );
3028
+ if ( data?.type == 'cluster' ) {
3029
+ let query = !data?.upload ? { _id: data.id } : { clusterName: data.clusterName, clientId: data.clientId };
3030
+ let clusterDetails = await clusterServices.findOneCluster( query, { stores: 1, clusterName: 1 } );
3003
3031
  if ( clusterDetails ) {
3004
3032
  assignedData = {
3005
3033
  checkFlag: true,
@@ -3007,13 +3035,15 @@ async function assignUsers( data ) {
3007
3035
  checkListName: data.checkListName,
3008
3036
  client_id: data?.clientId,
3009
3037
  clusterName: clusterDetails?.clusterName,
3010
- assignId: data.id,
3038
+ assignId: data?.id || clusterDetails?._id,
3011
3039
  };
3012
3040
  }
3013
3041
  } else {
3014
- let storeDetails = await storeService.findOne( { _id: data.id } );
3042
+ let query = !data?.upload ? { _id: data.id } : { storeName: data.storeName };
3043
+ let storeDetails = await storeService.findOne( query );
3015
3044
  if ( storeDetails ) {
3016
- let userDetails = await userService.findOne( { userEmail: storeDetails?.spocDetails?.email, clientId: data.clientId } );
3045
+ let email = data?.upload ? data.userEmail : storeDetails?.spocDetails?.email;
3046
+ let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
3017
3047
  if ( !userDetails ) {
3018
3048
  let userData = {
3019
3049
  userName: storeDetails.spocDetails?.[0]?.name,
@@ -3021,7 +3051,7 @@ async function assignUsers( data ) {
3021
3051
  mobileNumber: storeDetails.spocDetails?.[0]?.phone,
3022
3052
  clientId: data.clientId,
3023
3053
  };
3024
- createUser( userData );
3054
+ userDetails = createUser( userData );
3025
3055
  }
3026
3056
  assignedData = {
3027
3057
  store_id: storeDetails.storeId,
@@ -3031,18 +3061,19 @@ async function assignUsers( data ) {
3031
3061
  userEmail: userDetails.email,
3032
3062
  userPhone: userDetails?.mobileNumber,
3033
3063
  city: storeDetails?.storeProfile?.city,
3034
- country: storeDetails?.storeprofile?.country,
3064
+ country: storeDetails?.storeProfile?.country,
3035
3065
  checkFlag: true,
3036
3066
  checkListId: data.checklistId,
3037
3067
  checkListName: data.checkListName,
3038
3068
  client_id: data.clientId,
3039
- assignId: data.id,
3069
+ assignId: data?.id || storeDetails._id,
3040
3070
  };
3041
3071
  }
3042
3072
  }
3043
3073
  } else {
3044
3074
  if ( data.type == 'teams' ) {
3045
- let teamDetails = await teamsServices.findOneTeams( { _id: data.id }, { users: 1, teamName: 1 } );
3075
+ let query = !data?.upload ? { _id: data.id } : { teamName: data.teamName, clientId: data.clientId };
3076
+ let teamDetails = await teamsServices.findOneTeams( query, { users: 1, teamName: 1 } );
3046
3077
  if ( teamDetails ) {
3047
3078
  assignedData = {
3048
3079
  checkFlag: true,
@@ -3050,11 +3081,12 @@ async function assignUsers( data ) {
3050
3081
  checkListName: data.checkListName,
3051
3082
  client_id: data.clientId,
3052
3083
  teamName: teamDetails?.teamName,
3053
- assignId: data.id,
3084
+ assignId: data?.id || teamDetails?._id,
3054
3085
  };
3055
3086
  }
3056
3087
  } else {
3057
- let userDetails = await userService.findOne( { _id: { $in: data.id } } );
3088
+ let query = !data?.upload ? { _id: data.id } : { email: data.email, clientId: data.clientId };
3089
+ let userDetails = await userService.findOne( query );
3058
3090
  if ( userDetails ) {
3059
3091
  assignedData = {
3060
3092
  userId: userDetails._id,
@@ -3065,24 +3097,23 @@ async function assignUsers( data ) {
3065
3097
  checkListId: data.checklistId,
3066
3098
  checkListName: data.checkListName,
3067
3099
  client_id: data.clientId,
3068
- assignId: data.id,
3100
+ assignId: data?.id || userDetails?._id,
3069
3101
  };
3070
3102
  }
3071
3103
  }
3072
3104
  }
3073
- await assignedService.create( assignedData );
3105
+ if ( assignedData ) {
3106
+ await assignedService.create( assignedData );
3107
+ }
3074
3108
  }
3075
3109
 
3076
3110
  export async function checklistAssign( req, res ) {
3077
3111
  try {
3078
- if ( !req.body.type ) {
3079
- return res.sendError( 'Type is required', 400 );
3080
- }
3081
3112
  if ( !req.body.coverage ) {
3082
3113
  return res.sendError( 'coverage is required', 400 );
3083
3114
  }
3084
- if ( !req.body.id ) {
3085
- return res.sendError( 'coverage is required', 400 );
3115
+ if ( !req.body.idList ) {
3116
+ return res.sendError( 'Id list is required', 400 );
3086
3117
  }
3087
3118
  if ( !req.body.checklistId ) {
3088
3119
  return res.sendError( 'Checklist id is required', 400 );
@@ -3095,7 +3126,10 @@ export async function checklistAssign( req, res ) {
3095
3126
  return res.sendError( 'No data found', 204 );
3096
3127
  }
3097
3128
  req.body.checkListName = checklistDetails.checkListName;
3098
- await assignUsers( req.body );
3129
+ await Promise.all( req.body.idList.map( async ( ele ) => {
3130
+ let storeData = { ...req.body, type: ele.type, id: ele.id };
3131
+ await assignUsers( storeData );
3132
+ } ) );
3099
3133
  return res.sendSuccess( 'Details updated successfully' );
3100
3134
  } catch ( e ) {
3101
3135
  logger.error( { functionName: 'checklistAssign', error: e } );