find
чтобы он отдавал инфу именно из вложенного объекта в том числе.let { category } = req.params
let { page, limit, quantity, price_from } = req.query
category = await Category.findOne({ slug: category })
if (quantity) req.query.quantity = { $gt: quantity }
if (price_from) req.query.price = { $gt: price_from }
page = page || 1
limit = limit || 20
const paramsCategory = category.params
let params = {}
for (const el in req.query) {
const param = paramsCategory.find(val => val.property === el)
let prop = ''
if (param) {
if (param.type === 'number') prop = Number(req.query[el])
if (param.type === 'string') prop = req.query[el].toString()
if (param.type === 'variants') prop = req.query[el].toString()
const paramName = `params.${el}`
params[paramName] = prop
} else {
params[el] = req.query[el]
}
}
params = JSON.parse(JSON.stringify(params))
return Product.find({ category: category._id, ...params })
.limit(limit)
.skip(page * limit - limit)
.then(data => res.json(data))
.catch(error => next(ApiError.badRequest(error.message)))