Skip to content

Commit b0bf2ca

Browse files
modified user controller to use errors utils
1 parent d5937a6 commit b0bf2ca

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/controllers/user.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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)

src/utils/errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)