feat: add MongoDB search method, endpoints, and settings module
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-19 05:50:14 +03:30
parent 3829851566
commit acb2e5d623
18 changed files with 649 additions and 21 deletions
+2 -1
View File
@@ -4,7 +4,7 @@ const Role = require('./roleModel')
const roleService = require('./roleService')
exports.getAllRoles = catchAsync(async (req, res, next) => {
const roles = await roleService.getAllRoles()
const roles = await roleService.getAllRoles(req.query)
res.status(200).json({
status: 'success',
@@ -13,6 +13,7 @@ exports.getAllRoles = catchAsync(async (req, res, next) => {
})
})
exports.createRole = catchAsync(async (req, res, next) => {
const role = await roleService.createRole(req.body)
+11 -2
View File
@@ -1,10 +1,19 @@
const Role = require('./roleModel')
const AppError = require('../../globalErrorHandler/AppError')
module.exports.getAllRoles = async () => {
return Role.find({}).populate('permissions').sort({ createdAt: -1 })
module.exports.getAllRoles = async (query = {}) => {
const mongoQuery = {}
const search = (query.search || query.query || '').trim()
if (search) {
mongoQuery.$or = [
{ nativeName: { $regex: search, $options: 'i' } },
{ englishName: { $regex: search, $options: 'i' } },
]
}
return Role.find(mongoQuery).populate('permissions').sort({ createdAt: -1 })
}
module.exports.createRole = async (data) => {
const role = await Role.create(data)
return Role.findById(role._id).populate('permissions')