|
|
@@ -7,6 +7,7 @@ const { sequelize } = require('../database')
|
|
|
const crudController = (opts) => {
|
|
|
opts = defaults(opts)
|
|
|
const { Type } = opts
|
|
|
+ const options = Object.assign({}, opts.options)
|
|
|
|
|
|
const subset = async (req) => {
|
|
|
const subset = {}
|
|
|
@@ -34,14 +35,14 @@ const crudController = (opts) => {
|
|
|
[field.fieldName]: { [Op.like]: `%${req.query.q}%` }
|
|
|
}))
|
|
|
const where = { ...subset, [Op.or]: or }
|
|
|
- const data = await sanitize(req, await Type.findAll({ where }))
|
|
|
+ const data = await sanitize(req, await Type.findAll({ ...options, where }))
|
|
|
res.status(200).send(data)
|
|
|
} else if (res.query && res.query.ids) {
|
|
|
const ids = res.query.ids.split(',')
|
|
|
- const data = await sanitize(req, await Type.findAll({where: { ...(await subset(req)), id: { [Op.in]: ids }}}))
|
|
|
+ const data = await sanitize(req, await Type.findAll({ ...options, where: { ...(await subset(req)), id: { [Op.in]: ids }}}))
|
|
|
res.status(200).send(data)
|
|
|
} else {
|
|
|
- const data = await sanitize(req, await Type.findAll({where: { ...(await subset(req)) }}))
|
|
|
+ const data = await sanitize(req, await Type.findAll({ ...options, where: { ...(await subset(req)) }}))
|
|
|
res.status(200).send(data)
|
|
|
}
|
|
|
}
|