-
-
Save fuzzmz/315e2c73ec04137204bf to your computer and use it in GitHub Desktop.
Updated posts.js to expose old style JSON data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ### Read | |
* Find a post, by ID or Slug | |
* | |
* @public | |
* @param {{id_or_slug (required), context, status, include, ...}} options | |
* @return {Promise(Post)} Post | |
*/ | |
read: function read(options) { | |
var attrs = ['id', 'slug', 'status'], | |
data = _.pick(options, attrs); | |
options = _.omit(options, attrs); | |
// only published posts if no user is present | |
if (!(options.context && options.context.user)) { | |
data.status = 'published'; | |
} | |
if (options.include) { | |
options.include = prepareInclude(options.include); | |
} | |
return dataProvider.Post.findOne(data, options).then(function (result) { | |
if (result) { | |
return {posts: [result.toJSON()]}; | |
} | |
return Promise.reject(new errors.NotFoundError('Post not found.')); | |
}); | |
}, | |
readN: function readN(options) { | |
var attrs = ['id', 'slug', 'status'], | |
data = _.pick(options, attrs); | |
options = _.omit(options, attrs); | |
// only published posts if no user is present | |
if (!(options.context && options.context.user)) { | |
data.status = 'published'; | |
} | |
if (options.include) { | |
options.include = prepareInclude(options.include); | |
} | |
return dataProvider.Post.findOne(data, options).then(function (result) { | |
if (result) { | |
return result.toJSON(); | |
} | |
return Promise.reject(new errors.NotFoundError('Post not found.')); | |
}); | |
}, | |
/** | |
* ### Edit | |
* Update properties of a post | |
* | |
* @public | |
* @param {Post} object Post or specific properties to update | |
* @param {{id (required), context, include,...}} options | |
* @return {Promise(Post)} Edited Post | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment