Pārlūkot izejas kodu

Allow options for crud controller

Alan Colon 7 gadi atpakaļ
vecāks
revīzija
4527bbbb4b
1 mainītis faili ar 4 papildinājumiem un 3 dzēšanām
  1. 4 3
      lib/crud/controller.js

+ 4 - 3
lib/crud/controller.js

@@ -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)
     }
   }