From cb00aad4731468b9ab85cd7065eb36e40d5142c3 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 27 Aug 2013 22:03:59 -0700 Subject: [PATCH] Mark id arguments to be required --- lib/dao.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/dao.js b/lib/dao.js index 3191bc19..9dbdc7db 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -296,19 +296,19 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, callback) { DataAccessObject.exists = function exists(id, cb) { if (stillConnecting(this.dataSource, this, arguments)) return; - if (id) { + if (id !== undefined && id !== null && id !== '') { this.dataSource.connector.exists(this.modelName, id, cb); } else { - cb(new Error('Model::exists requires positive id argument')); + cb(new Error('Model::exists requires the id argument')); } }; // exists ~ remoting attributes setRemoting(DataAccessObject.exists, { description: 'Check whether a model instance exists in the data source', - accepts: {arg: 'id', type: 'any', description: 'Model id'}, + accepts: {arg: 'id', type: 'any', description: 'Model id', required: true}, returns: {arg: 'exists', type: 'any'}, - http: {verb: 'get', path: '/exists'} + http: {verb: 'get', path: '/:id/exists'} }); /** @@ -336,7 +336,7 @@ DataAccessObject.findById = function find(id, cb) { // find ~ remoting attributes setRemoting(DataAccessObject.findById, { description: 'Find a model instance by id from the data source', - accepts: {arg: 'id', type: 'any', description: 'Model id'}, + accepts: {arg: 'id', type: 'any', description: 'Model id', required: true}, returns: {arg: 'data', type: 'any', root: true}, http: {verb: 'get', path: '/:id'} }); @@ -530,7 +530,7 @@ DataAccessObject.deleteById = // deleteById ~ remoting attributes setRemoting(DataAccessObject.deleteById, { description: 'Delete a model instance by id from the data source', - accepts: {arg: 'id', type: 'any', description: 'Model id'}, + accepts: {arg: 'id', type: 'any', description: 'Model id', required: true}, http: {verb: 'del', path: '/:id'} });