【发布时间】:2021-12-26 05:13:18
【问题描述】:
我是新手后端开发人员,我正在尝试使用 Node.js 构建一个 REST API 以从 Pipedrive 赢得交易。我已经有一个使用 Axios 获得所有交易的功能,它工作得很好,但我需要过滤它的响应,只向我发送具有“赢得”状态的那些。我在 Pipedrive 中创建了一些具有不同状态的交易,例如“赢”、“输”和“开”。我有一个函数“getAllDeals”,它以 JSON 格式向我发送所有这些。我尝试以多种不同的方式对其进行调整,但均未成功。
我在路由 /deals 中调用了这个函数:
router.get('/deals', controller.getAllDeals)
这是我的功能,正在运行,以获取所有交易:
async getAllDeals(_, res){
try {
const response = await axios.get(`${PIPE_URL}?api_token=${PIPE_TOKEN}`)
return res.json(response.data)
}
catch (err) {
console.log(err)
}
}
这是我最后一次尝试过滤其响应数据:
async getAllDeals(_, res){
try {
const response = await axios.get(`${PIPE_URL}?api_token=${PIPE_TOKEN}`)
const deals = res.json(response.data)
const dealsWon = response.where(deals, {status: "won"})
return dealsWon
}
catch (err) {
console.log(err)
}
}
我希望有一个简单的方法来做到这一点。
【问题讨论】:
标签: node.js json rest filter axios