UNPKG

sails-base

Version:

sails1.0+扩展基础包,包含用户体系权限校验及model的attr,action的inputs入参提示语自定义功能

30 lines (23 loc) 744 B
/** * @Filename is-model-found.js * @Description 资源是否存在校验策略 * @author kenchar (kenchar.lv@gmail.com) * @date 2019/07/25 */ module.exports = async function (req, res, proceed) { let modelId = req.param('id'); let modelName; if(_.has(req.options,'action')) modelName = req.options.action.split('/')[0]; else modelName = req.options.model || req.options.controller; if (!modelName || _.isEmpty(modelId)) return res.forbidden(new NullError()); if (req.model && _.isEqual(req.model.id, modelId)) { return proceed(); } let model = await sails.models[modelName].findOne(req.param('id')); if (model) { req.model = model; return proceed(); } return res.forbidden(new NullError()); };