Merge pull request #135 from albertoleal/ConvertNullToNotFoundError

ConvertNulltoNotFoundError when calling DataAccessObject.findOne via rest
This commit is contained in:
Raymond Feng 2014-06-18 23:00:30 -07:00
commit 26501eaa2e
1 changed files with 12 additions and 11 deletions

View File

@ -78,7 +78,7 @@ DataAccessObject._forDB = function (data) {
* }); * });
* ``` * ```
* Note: You must include a callback and use the created model provided in the callback if your code depends on your model being * Note: You must include a callback and use the created model provided in the callback if your code depends on your model being
* saved or having an ID. * saved or having an ID.
* *
* @param {Object} data Optional data object * @param {Object} data Optional data object
* @param {Function} callback Callback function called with these arguments: * @param {Function} callback Callback function called with these arguments:
@ -215,7 +215,7 @@ function stillConnecting(dataSource, obj, args) {
/** /**
* Update or insert a model instance: update exiting record if one is found, such that parameter `data.id` matches `id` of model instance; * Update or insert a model instance: update exiting record if one is found, such that parameter `data.id` matches `id` of model instance;
* otherwise, insert a new record. * otherwise, insert a new record.
* *
* NOTE: No setters, validations, or hooks are applied when using upsert. * NOTE: No setters, validations, or hooks are applied when using upsert.
* `updateOrCreate` is an alias * `updateOrCreate` is an alias
* @param {Object} data The model instance data * @param {Object} data The model instance data
@ -332,7 +332,7 @@ setRemoting(DataAccessObject.exists, {
/** /**
* Find model instance by ID. * Find model instance by ID.
* *
* Example: * Example:
* ```js * ```js
* User.findById(23, function(err, user) { * User.findById(23, function(err, user) {
@ -573,7 +573,7 @@ DataAccessObject._coerce = function (where) {
* Find all instances of Model that match the specified query. * Find all instances of Model that match the specified query.
* Fields used for filter and sort should be declared with `{index: true}` in model definition. * Fields used for filter and sort should be declared with `{index: true}` in model definition.
* See [Querying models](http://docs.strongloop.com/display/DOC/Querying+models) for more information. * See [Querying models](http://docs.strongloop.com/display/DOC/Querying+models) for more information.
* *
* For example, find the second page of ten users over age 21 in descending order exluding the password property. * For example, find the second page of ten users over age 21 in descending order exluding the password property.
* *
* ```js * ```js
@ -590,7 +590,7 @@ DataAccessObject._coerce = function (where) {
* ``` * ```
* *
* @options {Object} [query] Optional JSON object that specifies query criteria and parameters. * @options {Object} [query] Optional JSON object that specifies query criteria and parameters.
* @property {Object} where Search criteria in JSON format `{ key: val, key2: {gt: 'val2'}}`. * @property {Object} where Search criteria in JSON format `{ key: val, key2: {gt: 'val2'}}`.
* Operations: * Operations:
* - gt: > * - gt: >
* - gte: >= * - gte: >=
@ -602,7 +602,7 @@ DataAccessObject._coerce = function (where) {
* - neq: != * - neq: !=
* - like: LIKE * - like: LIKE
* - nlike: NOT LIKE * - nlike: NOT LIKE
* *
* You can also use `and` and `or` operations. See [Querying models](http://docs.strongloop.com/display/DOC/Querying+models) for more information. * You can also use `and` and `or` operations. See [Querying models](http://docs.strongloop.com/display/DOC/Querying+models) for more information.
* @property {String|Object|Array} include Allows you to load relations of several objects and optimize numbers of requests. * @property {String|Object|Array} include Allows you to load relations of several objects and optimize numbers of requests.
* Format examples; * Format examples;
@ -621,7 +621,7 @@ DataAccessObject._coerce = function (where) {
* - `['foo', 'bar']` - include the foo and bar properties. Format: * - `['foo', 'bar']` - include the foo and bar properties. Format:
* - `{foo: true}` - include only foo * - `{foo: true}` - include only foo
* - `{bat: false}` - include all properties, exclude bat * - `{bat: false}` - include all properties, exclude bat
* *
* @param {Function} callback Required callback function. Call this function with two arguments: `err` (null or Error) and an array of instances. * @param {Function} callback Required callback function. Call this function with two arguments: `err` (null or Error) and an array of instances.
*/ */
@ -767,7 +767,8 @@ setRemoting(DataAccessObject.findOne, {
description: 'Find first instance of the model matched by filter from the data source', description: 'Find first instance of the model matched by filter from the data source',
accepts: {arg: 'filter', type: 'object', description: 'Filter defining fields, where, orderBy, offset, and limit'}, accepts: {arg: 'filter', type: 'object', description: 'Filter defining fields, where, orderBy, offset, and limit'},
returns: {arg: 'data', type: 'object', root: true}, returns: {arg: 'data', type: 'object', root: true},
http: {verb: 'get', path: '/findOne'} http: {verb: 'get', path: '/findOne'},
rest: {after: convertNullToNotFoundError}
}); });
/** /**
@ -779,7 +780,7 @@ setRemoting(DataAccessObject.findOne, {
// removed matching products // removed matching products
* }); * });
* ```` * ````
* *
* @param {Object} [where] Optional object that defines the criteria. This is a "where" object. Do NOT pass a filter object. * @param {Object} [where] Optional object that defines the criteria. This is a "where" object. Do NOT pass a filter object.
* @param {Function} [cb] Callback called with (err) * @param {Function} [cb] Callback called with (err)
*/ */
@ -814,7 +815,7 @@ DataAccessObject.remove = DataAccessObject.deleteAll = DataAccessObject.destroyA
}; };
/** /**
* Delete the record with the specified ID. * Delete the record with the specified ID.
* Aliases are `destroyById` and `deleteById`. * Aliases are `destroyById` and `deleteById`.
* @param {*} id The id value * @param {*} id The id value
* @param {Function} cb Callback called with (err) * @param {Function} cb Callback called with (err)
@ -843,7 +844,7 @@ setRemoting(DataAccessObject.deleteById, {
/** /**
* Return count of matched records. Optional query parameter allows you to count filtered set of model instances. * Return count of matched records. Optional query parameter allows you to count filtered set of model instances.
* Example: * Example:
* *
*```js *```js
* User.count({approved: true}, function(err, count) { * User.count({approved: true}, function(err, count) {
* console.log(count); // 2081 * console.log(count); // 2081