Merge pull request #135 from albertoleal/ConvertNullToNotFoundError
ConvertNulltoNotFoundError when calling DataAccessObject.findOne via rest
This commit is contained in:
commit
26501eaa2e
23
lib/dao.js
23
lib/dao.js
|
@ -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
|
||||
* saved or having an ID.
|
||||
* saved or having an ID.
|
||||
*
|
||||
* @param {Object} data Optional data object
|
||||
* @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;
|
||||
* otherwise, insert a new record.
|
||||
*
|
||||
*
|
||||
* NOTE: No setters, validations, or hooks are applied when using upsert.
|
||||
* `updateOrCreate` is an alias
|
||||
* @param {Object} data The model instance data
|
||||
|
@ -332,7 +332,7 @@ setRemoting(DataAccessObject.exists, {
|
|||
|
||||
/**
|
||||
* Find model instance by ID.
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
* ```js
|
||||
* User.findById(23, function(err, user) {
|
||||
|
@ -573,7 +573,7 @@ DataAccessObject._coerce = function (where) {
|
|||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* ```js
|
||||
|
@ -590,7 +590,7 @@ DataAccessObject._coerce = function (where) {
|
|||
* ```
|
||||
*
|
||||
* @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:
|
||||
* - gt: >
|
||||
* - gte: >=
|
||||
|
@ -602,7 +602,7 @@ DataAccessObject._coerce = function (where) {
|
|||
* - neq: !=
|
||||
* - like: 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.
|
||||
* @property {String|Object|Array} include Allows you to load relations of several objects and optimize numbers of requests.
|
||||
* Format examples;
|
||||
|
@ -621,7 +621,7 @@ DataAccessObject._coerce = function (where) {
|
|||
* - `['foo', 'bar']` - include the foo and bar properties. Format:
|
||||
* - `{foo: true}` - include only foo
|
||||
* - `{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.
|
||||
*/
|
||||
|
||||
|
@ -767,7 +767,8 @@ setRemoting(DataAccessObject.findOne, {
|
|||
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'},
|
||||
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
|
||||
* });
|
||||
* ````
|
||||
*
|
||||
*
|
||||
* @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)
|
||||
*/
|
||||
|
@ -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`.
|
||||
* @param {*} id The id value
|
||||
* @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.
|
||||
* Example:
|
||||
*
|
||||
*
|
||||
*```js
|
||||
* User.count({approved: true}, function(err, count) {
|
||||
* console.log(count); // 2081
|
||||
|
|
Loading…
Reference in New Issue