Skip to content

Commit

Permalink
Merge pull request #470 from pqv199x/get-reward-master
Browse files Browse the repository at this point in the history
update get reward api
  • Loading branch information
thanhson1085 authored Oct 31, 2018
2 parents 2ce0289 + 7bd4d5e commit df3a003
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions server/src/api/RewardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit df3a003

Please sign in to comment.