mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 01:03:23 +03:00
57a5b6a188
closes #2622, ref #2125
24 lines
733 B
JavaScript
24 lines
733 B
JavaScript
// # API Utils
|
|
// Shared helpers for working with the API
|
|
var when = require('when'),
|
|
_ = require('lodash'),
|
|
utils;
|
|
|
|
utils = {
|
|
/**
|
|
* ### 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
|
|
*/
|
|
checkObject: function (object, docName) {
|
|
if (_.isEmpty(object) || _.isEmpty(object[docName]) || _.isEmpty(object[docName][0])) {
|
|
return when.reject({type: 'BadRequest', message: 'No root key (\'' + docName + '\') provided.'});
|
|
}
|
|
return when.resolve(object);
|
|
}
|
|
};
|
|
|
|
module.exports = utils; |