I have a User model and a Follower model which has HasManyThrough relation with User for the follower and followee. How can I change the default __get__followers method parameters?
3
votes
2 Answers
5
votes
I figured out that I can juse add a new remote method the normal way.
loopback.remoteMethod(
UserModel.prototype.getFollows,
{
description: 'Get the users who are followed by the user',
accepts: [
{arg: 'page', type: 'Number', http: {source: 'query'}, required: true}
],
returns: {arg: 'data', type: 'object'},
http: {verb: 'get', path: '/follows'},
isStatic: false,
}
);
0
votes
Yet another way. Tree hasMany Leaves and we want to override the __get__leaves relation handler of a Tree.
/**
* Before Remote handler
*
* @param {Object} ctx - Context
* @param {Function} next - Callback function
*/
Tree.beforeRemote('**', function (ctx, unused, next) {
if (ctx.method.name === '__get__leaves') {
return Tree.getLeaves(ctx)
}
next()
})
/**
* Override Relation handler
*
* @param {Object} ctx - Context
*/
Tree.getLeaves = (ctx) => {
ctx.res.sendStatus(200)
}