我需要从外部文件导出功能。
const filter = require('../controllers/filter.js');
exports.get = async function (req, res, next) {
filter.validateId(req, res, next);
const db = req.app.get('db');
let id = req.params.id;
let user;
try {
user = await db.models.user.findByPk(id);
} catch (err) {
next(err);
}
res.json(user);
};
文件结构: enter image description here
但是我得到了错误:
{NotFoundError:找不到 在E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ app.js:43:8 在Layer.handle上[作为handle_request](E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ layer.js:95:5) 在trim_prefix(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:317:13) 在E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:284:7 在Function.process_params(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:335:12) 在下一个(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:275:10) 在E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:635:15 在下一个(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:260:14) 在Function.handle(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:174:3) 在路由器上(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:47:12) 在Layer.handle上[作为handle_request](E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ layer.js:95:5) 在trim_prefix(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:317:13) 在E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:284:7 在Function.process_params(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:335:12) 在下一个(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ express \ lib \ router \ index.js:275:10) 在SendStream.error(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ serve-static \ index.js:121:7) 在SendStream.emit(events.js:189:13) 在SendStream.error(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ send \ index.js:270:17) 在SendStream.onStatError(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ send \ index.js:421:12) 在下一个(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ send \ index.js:736:16) 在onstat(E:\ Dropbox \ BigDeal \ clone \ BigDealExpressJSTest \ node_modules \ send \ index.js:725:14) 在FSReqWrap.oncomplete(fs.js:154:21)消息:“未找到”} GET / 4 404 48.713毫秒-100
答案 0 :(得分:0)
我认为model.findAll({
where: {
start_datetime: {
$gte: Sequelize.literal('NOW() - INTERVAL "7d"'),
}
}
})
指向错误的位置(假设提供的代码在require
中)。
应该是:
userController.js