Skip to content

Commit

Permalink
Merge pull request #13 from GolosChain/8-delegation
Browse files Browse the repository at this point in the history
fix: add filter arguments #8
b1acksun authored Sep 27, 2019
2 parents 71b9842 + 03864de commit a8906f7
Showing 2 changed files with 38 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/controllers/BlockChainMongo.js
Original file line number Diff line number Diff line change
@@ -174,12 +174,28 @@ class BlockChainMongo extends BasicController {
return grantsMap;
}

async getDelegations({ offset, limit }) {
async getDelegations({ userId, offset, limit, direction }) {
const db = this._client.db('_CYBERWAY_gls_vesting');
const collection = db.collection('delegation');

const directionFilter = [];

if (direction === 'out') {
directionFilter.push({ delegator: userId });
}

if (direction === 'in') {
directionFilter.push({ delegatee: userId });
}

if (direction === 'all') {
directionFilter.push({ delegator: userId }, { delegatee: userId });
}

const items = await collection
.find({})
.find({
$or: directionFilter,
})
.project({ _id: false, id: false, _SERVICE_: false })
.skip(offset)
.limit(limit)
22 changes: 20 additions & 2 deletions src/services/Connector.js
Original file line number Diff line number Diff line change
@@ -14,10 +14,18 @@ class Connector extends BasicConnector {
await super.start({
serverRoutes: {
getDelegations: {
inherits: ['pagination'],
inherits: ['pagination', 'userSpecific'],
handler: this._bcMongo.getDelegations,
scope: this._bcMongo,
validation: {},
validation: {
properties: {
direction: {
type: 'string',
default: 'all',
enum: ['in', 'out', 'all'],
},
},
},
},
getValidators: {
inherits: ['pagination'],
@@ -76,6 +84,16 @@ class Connector extends BasicConnector {
},
},
},
userSpecific: {
validation: {
required: ['userId'],
properties: {
userId: {
type: 'string',
},
},
},
},
},
},
});

0 comments on commit a8906f7

Please sign in to comment.