Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add filter arguments #8 #13

Merged
merged 4 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/controllers/BlockChainMongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions src/services/Connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -76,6 +84,16 @@ class Connector extends BasicConnector {
},
},
},
userSpecific: {
validation: {
required: ['userId'],
properties: {
userId: {
type: 'string',
},
},
},
},
},
},
});
Expand Down