File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -135,8 +135,12 @@ export const searchUserByName = async (req, res) => {
135135 }
136136
137137 try {
138- const searchedUser = await User . searchUserByName ( name )
139- return sendDataResponse ( { user : searchedUser } )
138+ const users = await User . searchUserByName ( name )
139+
140+ if ( users . length === 0 ) {
141+ return sendMessageResponse ( res , 404 , ERR . NAME_USER_NOT_FOUND )
142+ }
143+ return sendDataResponse ( { users } )
140144 } catch ( e ) {
141145 console . error ( 'Error searching for users:' , e )
142146 return sendMessageResponse ( res , 500 , ERR . UNABLE_TO_SEARCH_USER )
Original file line number Diff line number Diff line change @@ -28,5 +28,6 @@ export default {
2828 UNABLE_TO_CREATE_COHORT : 'Unable to create a new cohort.' ,
2929 NAME_REQUIRED : 'A name must be provided.' ,
3030 NAME_FORMATTING : 'Names can only contain letters' ,
31- UNABLE_TO_SEARCH_USER : 'Unable to search for users'
31+ UNABLE_TO_SEARCH_USER : 'Unable to search for users' ,
32+ NAME_USER_NOT_FOUND : 'user not found by that name'
3233}
You can’t perform that action at this time.
0 commit comments