表达.get方法回调函数问题



tour.route.js代码:

app.get(tour_controller.getTourById)
tour_controller.js
getTourById = handler.getOne(TourModel);

handler.js

exports.getOne = (Model, popOptions) => {
catchAsync(async (req, res, next) => {
let query = Model.findById(req.params.id);
if (popOptions) {`your text`
query = query.populate(popOptions);
}
const docs = await query;
if (!docs) {
return next(
new apiError('No documents found with ID: ' + req.params.id, 404)
);
}
res.status(200).json({
status: 'succeed!',
data: docs,
});
});
};
NPM启动时显示的问题

我被困在这里,同样的事情适用于。post,。patch和。delete方法,但对于。get方法

显示错误

您忘了返回

exports.getOne = (Model, popOptions) => {
return catchAsync(async (req, res, next) => {
// ...
});
};

最新更新