Skip to content

Instantly share code, notes, and snippets.

@gocreating
Forked from pulkitsinghal/my-model.js
Created September 20, 2018 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gocreating/2761261d6782b7720c6948f1375f4f06 to your computer and use it in GitHub Desktop.
Save gocreating/2761261d6782b7720c6948f1375f4f06 to your computer and use it in GitHub Desktop.
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