2014-06-03 17:05:25 +04:00
|
|
|
// # API Utils
|
|
|
|
// Shared helpers for working with the API
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
var when = require('when'),
|
|
|
|
_ = require('lodash'),
|
2014-06-20 13:15:01 +04:00
|
|
|
errors = require('../errors'),
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
utils;
|
|
|
|
|
|
|
|
utils = {
|
2014-06-03 17:05:25 +04:00
|
|
|
/**
|
|
|
|
* ### Check Object
|
|
|
|
* Check an object passed to the API is in the correct format
|
|
|
|
*
|
|
|
|
* @param {Object} object
|
|
|
|
* @param {String} docName
|
|
|
|
* @returns {Promise(Object)} resolves to the original object if it checks out
|
|
|
|
*/
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
checkObject: function (object, docName) {
|
|
|
|
if (_.isEmpty(object) || _.isEmpty(object[docName]) || _.isEmpty(object[docName][0])) {
|
2014-06-20 13:15:01 +04:00
|
|
|
return when.reject(new errors.BadRequestError('No root key (\'' + docName + '\') provided.'));
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 16:41:19 +04:00
|
|
|
}
|
|
|
|
return when.resolve(object);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = utils;
|