gregor
gregor

Reputation: 3

StrongLoop overriding PUT built in method

I am facing an issue trying to override StrongLoop built in method for PUT request.

So in model.js file I am using:

  Model.on('attached', function(){
    Model.updateAttributes = function(data, id, cb){
      cb(null,'This is a overridden method');
    }; 
}

But when I call the endpoint with a PUT /api/v1/models/1 and payload this function does not get executed but the built in one. I also tried to use other function instead of updateAttributes but without any success like for example:

Model.updateAll = function([where], data, cb) {
  cb(null, 'this is a overriden method');
}

Model.create = function(data, cb) {
  cb(null, 'this is overriden method');
}

Thanks for helping me out.

Upvotes: 0

Views: 136

Answers (1)

richardpringle
richardpringle

Reputation: 781

Instead of overriding the method, you can disable and attach a new method to the same endpoint as follows:

Model.disableRemoteMethodByName('updateAttributes');

Model.newMethod = function(cb) {
  cb(null, 'new message');
}

Model.remoteMethod('newMethod', {
  returns: {
    arg: 'msg'
  },
  http: {
    verb: 'put',
    path: '/'
  }
});

Upvotes: 4

Related Questions