-
-
Save gocreating/2761261d6782b7720c6948f1375f4f06 to your computer and use it in GitHub Desktop.
Non-Static (instance) remote methods for loopback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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