Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Non-Static (instance) remote methods for loopback
var loopback = require('loopback');
// HINT(s):
// Getting the app object: http://docs.strongloop.com/display/public/LB/Working+with+LoopBack+objects
// From a model script: http://docs.strongloop.com/display/public/LB/Working+with+LoopBack+objects#WorkingwithLoopBackobjects-Fromamodelscript
module.exports = function(StoreModel) {
StoreModel.prototype.instanceRemoteMethodSignature = function(cb) {
console.log('print this instance object: ', this);
cb(null);
};
StoreModel.remoteMethod(
'__get__instance-remote-method-signature',
{
isStatic: false,
accepts: [],
http: {path:'/instance-remote-method-signature', verb: 'get'}
}
);
StoreModel.staticMethodSignature = function(id, cb) {
console.log('print this instance object: ', this);
StoreModel.findById(id,function(err, instances){
if(err){
cb(err);
}
console.log('print object: ', instances);
cb(null);
});
};
StoreModel.remoteMethod(
'__get__static-method-signature',
{
isStatic: false,
accepts: [
{arg: 'id', type: 'number', required: true}
],
http: {path:'/:id/static-method-signature', verb: 'get'}
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.