From fbf0e35f1d633ed5673006526a88899fdecde637 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Mon, 15 Jul 2013 19:45:27 -0700 Subject: [PATCH] Remove updateAttribute as remote method --- lib/models/model.js | 114 +++++++++++++++++++-------------------- test/data-source.test.js | 1 - 2 files changed, 56 insertions(+), 59 deletions(-) diff --git a/lib/models/model.js b/lib/models/model.js index b77433ad..e2cdb53d 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -17,64 +17,6 @@ Model.shared = true; * For **remoting**. Construct objects when calling instance methods remotely. */ -Model.sharedCtor = function (data, id, fn) { - var ModelCtor = this; - - if(typeof data === 'function') { - fn = data; - data = null; - id = null; - } else if (typeof id === 'function') { - fn = id; - - if(typeof data !== 'object') { - id = data; - data = null; - } else { - id = null; - } - } - - if(id && data) { - var model = new ModelCtor(data); - model.id = id; - fn(null, model); - } else if(data) { - fn(null, new ModelCtor(data)); - } else if(id) { - ModelCtor.find(id, function (err, model) { - if(err) { - fn(err); - } else if(model) { - fn(null, model); - } else { - err = new Error('could not find a model with id ' + id); - err.statusCode = 404; - - fn(err); - } - }); - } else { - fn(new Error('must specify an id or data')); - } -} - -// before remote hook -Model.beforeRemote = function (name, fn) { - var self = this; - if(this.app) { - var remotes = this.app.remotes(); - remotes.before(self.pluralModelName + '.' + name, function (ctx, next) { - fn(ctx, ctx.result, next); - }); - } else { - var args = arguments; - this.once('attached', function () { - self.beforeRemote.apply(self, args); - }); - } -} - // after remote hook Model.afterRemote = function (name, fn) { var self = this; @@ -103,6 +45,62 @@ Model.setup = function () { // list Model.acl = []; + Model.sharedCtor = function (data, id, fn) { + if(typeof data === 'function') { + fn = data; + data = null; + id = null; + } else if (typeof id === 'function') { + fn = id; + + if(typeof data !== 'object') { + id = data; + data = null; + } else { + id = null; + } + } + + if(id && data) { + var model = new ModelCtor(data); + model.id = id; + fn(null, model); + } else if(data) { + fn(null, new ModelCtor(data)); + } else if(id) { + ModelCtor.find(id, function (err, model) { + if(err) { + fn(err); + } else if(model) { + fn(null, model); + } else { + err = new Error('could not find a model with id ' + id); + err.statusCode = 404; + + fn(err); + } + }); + } else { + fn(new Error('must specify an id or data')); + } + } + + // before remote hook + ModelCtor.beforeRemote = function (name, fn) { + var self = this; + if(this.app) { + var remotes = this.app.remotes(); + remotes.before(self.pluralModelName + '.' + name, function (ctx, next) { + fn(ctx, ctx.result, next); + }); + } else { + var args = arguments; + this.once('attached', function () { + self.beforeRemote.apply(self, args); + }); + } + } + ModelCtor.sharedCtor.accepts = [ {arg: 'data', type: 'object', http: {source: 'body'}}, {arg: 'id', type: 'any', http: {source: 'url'}} diff --git a/test/data-source.test.js b/test/data-source.test.js index fb33ead4..832a9d44 100644 --- a/test/data-source.test.js +++ b/test/data-source.test.js @@ -61,7 +61,6 @@ describe('DataSource', function() { existsAndShared('isNewRecord', false); existsAndShared('_adapter', false); existsAndShared('destroy', true); - existsAndShared('updateAttribute', true); existsAndShared('updateAttributes', true); existsAndShared('reload', true);