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:
@@ -1,10 +1,19 @@
|
||||
const Category = require('./categoryModel')
|
||||
const AppError = require('../../globalErrorHandler/AppError')
|
||||
|
||||
module.exports.getAllCategories = async () => {
|
||||
return Category.find().populate('features')
|
||||
module.exports.getAllCategories = 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 Category.find(mongoQuery).populate('features')
|
||||
}
|
||||
|
||||
|
||||
module.exports.createCategory = async (data) => {
|
||||
return Category.create(data, null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user