【发布时间】:2021-11-01 12:31:57
【问题描述】:
我的项目使用 express。我想重用当前在控制器上的一些代码。
getCustomersByCompanyId = async (req, res) => {
... some logic ...
}
getCustomersByCompanyId = async (req, res) => {
const companyId = getCompanyByName(req.params.name)._id;
// Here I want to do some kind of a wrapper around getCustomersByCompanyId
// I have the id. But it seems that I need to send req contains that contains the id and not just the id as an argument... what's the best practice?
return getCustomersByCompanyId(companyId); // <---- In other syntaxes I would do something like...
}
【问题讨论】:
-
让函数带一个ID,并把控制器函数分开,让它根据请求调用另一个具有正确ID的函数。
标签: node.js express controller