feat: add MongoDB search method, endpoints, and settings module
deploy-chabokan / deploy (push) Canceled after 0s
deploy-chabokan / deploy (push) Canceled after 0s
This commit is contained in:
@@ -159,10 +159,19 @@ const loginUser = async (email, password) => {
|
||||
return { token: signToken(user._id), user }
|
||||
}
|
||||
|
||||
const getAllUsers = async () => {
|
||||
return User.find({}).populate('role').sort({ createdAt: -1 })
|
||||
const getAllUsers = async (query = {}) => {
|
||||
const mongoQuery = {}
|
||||
const search = (query.search || query.query || '').trim()
|
||||
if (search) {
|
||||
mongoQuery.$or = [
|
||||
{ name: { $regex: search, $options: 'i' } },
|
||||
{ email: { $regex: search, $options: 'i' } },
|
||||
]
|
||||
}
|
||||
return User.find(mongoQuery).populate('role').sort({ createdAt: -1 })
|
||||
}
|
||||
|
||||
|
||||
const getUser = async (userId) => {
|
||||
const user = await User.findById(userId).populate('role')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user