From 7bd4d5e9c6655f2678e4da4d16d16eb3ab65f89d Mon Sep 17 00:00:00 2001 From: Vu Pham Date: Wed, 31 Oct 2018 17:19:59 +0700 Subject: [PATCH] update get reward api --- server/src/api/RewardController.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/server/src/api/RewardController.js b/server/src/api/RewardController.js index 7cdd9c30..f862f66f 100644 --- a/server/src/api/RewardController.js +++ b/server/src/api/RewardController.js @@ -60,12 +60,25 @@ RewardController.get('/rewards/total/:slug/:fromEpoch/:toEpoch', async (req, res } }) -RewardController.get('/expose/rewards/:slug', async (req, res) => { +RewardController.post('/expose/rewards', async (req, res) => { try { - const address = req.params.slug.toLowerCase() || '' - const limit = !isNaN(req.query.limit) ? parseInt(req.query.limit) : 0 + const address = req.body.address || null + const owner = req.body.owner || null + const limit = !isNaN(req.body.limit) ? parseInt(req.body.limit) : 0 + let params = {} + + if (owner) { + params = { + validator: address.toLowerCase(), + address: owner.toLowerCase() + } + } else { + params = { + address: address.toLowerCase() + } + } - const reward = await db.Reward.find({ address: address }).sort({ _id: -1 }).limit(limit) + const reward = await db.Reward.find(params).sort({ _id: -1 }).limit(limit) res.send(reward) } catch (e) {