Skip to content

Commit ccd84d4

Browse files
reverted changes made regarding users searching in branch #36-cohort_entity_update
1 parent b0bf2ca commit ccd84d4

File tree

5 files changed

+4
-92
lines changed

5 files changed

+4
-92
lines changed

src/controllers/user.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import User from '../domain/user.js'
22
import dbClient from '../utils/dbClient.js'
33
import { sendDataResponse, sendMessageResponse } from '../utils/responses.js'
4-
import { validateCanModify, isValidName } from '../utils/validationFunctions.js'
4+
import { validateCanModify } from '../utils/validationFunctions.js'
55
import * as validation from '../utils/validationFunctions.js'
66
import ERR from '../utils/errors.js'
77

@@ -122,27 +122,3 @@ export const deleteUserById = async (req, res) => {
122122
return sendDataResponse(res, 500, { error: ERR.DELETE_GENERIC_ERROR })
123123
}
124124
}
125-
126-
export const searchUserByName = async (req, res) => {
127-
const { name } = req.body
128-
129-
if (!name) {
130-
return sendMessageResponse(res, 400, ERR.NAME_REQUIRED)
131-
}
132-
133-
if (!isValidName(name)) {
134-
return sendMessageResponse(res, 400, ERR.NAME_FORMATTING)
135-
}
136-
137-
try {
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 })
144-
} catch (e) {
145-
console.error('Error searching for users:', e)
146-
return sendMessageResponse(res, 500, ERR.UNABLE_TO_SEARCH_USER)
147-
}
148-
}

src/domain/user.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -236,54 +236,6 @@ export default class User {
236236
})
237237
return updatedUser
238238
}
239-
240-
static async searchUserByName(name) {
241-
const splitName = name.split(' ')
242-
243-
const searchedUser = await dbClient.user.findMany({
244-
where: {
245-
OR: [
246-
{
247-
firstName: {
248-
contains: name,
249-
mode: 'insensitive'
250-
}
251-
},
252-
{
253-
lastName: {
254-
contains: name,
255-
mode: 'insensitive'
256-
}
257-
},
258-
{
259-
AND:
260-
splitName.length > 1
261-
? [
262-
{
263-
firstName: {
264-
contains: splitName[0],
265-
mode: 'insensitive'
266-
}
267-
},
268-
{
269-
lastName: { contains: splitName[1], mode: 'insensitive' }
270-
}
271-
]
272-
: []
273-
}
274-
]
275-
},
276-
include: {
277-
profile: true,
278-
cohort: true,
279-
posts: true,
280-
deliveryLogs: true,
281-
notesCreated: true,
282-
notesReceived: true
283-
}
284-
})
285-
return searchedUser
286-
}
287239
}
288240

289241
async function _findByUniqueAsATeacher(id) {

src/routes/user.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
getById,
55
getAll,
66
updateById,
7-
deleteUserById,
8-
searchUserByName
7+
deleteUserById
98
} from '../controllers/user.js'
109
import { validateAuthentication } from '../middleware/auth.js'
1110

@@ -16,6 +15,5 @@ router.get('/', validateAuthentication, getAll)
1615
router.get('/:id', validateAuthentication, getById)
1716
router.delete('/:id', validateAuthentication, deleteUserById)
1817
router.patch('/:id', validateAuthentication, updateById)
19-
router.get('/search', validateAuthentication, searchUserByName)
2018

2119
export default router

src/utils/errors.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,5 @@ export default {
2525
INTERNAL_ERROR: 'The server was unable to complete this request',
2626
MISSING_CONTENT: 'The content is missing from the request body',
2727
INVALID_NOTE_CONTENT: 'Some text must be provided in order to create a note',
28-
UNABLE_TO_CREATE_COHORT: 'Unable to create a new cohort.',
29-
NAME_REQUIRED: 'A name must be provided.',
30-
NAME_FORMATTING: 'Names can only contain letters',
31-
UNABLE_TO_SEARCH_USER: 'Unable to search for users',
32-
NAME_USER_NOT_FOUND: 'user not found by that name'
28+
UNABLE_TO_CREATE_COHORT: 'Unable to create a new cohort.'
3329
}

src/utils/validationFunctions.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
emailRegex,
3-
passwordRegex,
4-
dateRegex,
5-
nameRegex
6-
} from './regexMatchers.js'
1+
import { emailRegex, passwordRegex, dateRegex } from './regexMatchers.js'
72
import ERR from './errors.js'
83

94
export function register(email, password) {
@@ -59,8 +54,3 @@ export function validateCanModify(req) {
5954
}
6055
return true
6156
}
62-
63-
export function isValidName(name) {
64-
nameRegex.test(name)
65-
return true
66-
}

0 commit comments

Comments
 (0)