diff --git a/core/server/api/posts.js b/core/server/api/posts.js index 99f7362cc5..97b381105c 100644 --- a/core/server/api/posts.js +++ b/core/server/api/posts.js @@ -1,6 +1,8 @@ +'use strict'; + // # Posts API // RESTful API for the Post resource -var Promise = require('bluebird'), +const Promise = require('bluebird'), _ = require('lodash'), pipeline = require('../lib/promise/pipeline'), localUtils = require('./utils'), @@ -13,8 +15,9 @@ var Promise = require('bluebird'), allowedIncludes = [ 'created_by', 'updated_by', 'published_by', 'author', 'tags', 'fields', 'authors', 'authors.roles' ], - unsafeAttrs = ['author_id', 'status', 'authors'], - posts; + unsafeAttrs = ['author_id', 'status', 'authors']; + +let posts; /** * ### Posts API Methods @@ -220,7 +223,8 @@ posts = { /** * ## Destroy - * Delete a post, cleans up tag relations, but not unused tags + * Delete a post, cleans up tag relations, but not unused tags. + * You can only delete a post by `id`. * * @public * @param {{id (required), context,...}} options @@ -234,17 +238,14 @@ posts = { * @param {Object} options */ function deletePost(options) { - var Post = models.Post, - data = _.defaults({status: 'all'}, options), - fetchOpts = _.defaults({require: true, columns: 'id'}, options); + const opts = _.defaults({require: true}, options); - return Post.findOne(data, fetchOpts).then(function () { - return Post.destroy(options).return(null); - }).catch(Post.NotFoundError, function () { - throw new common.errors.NotFoundError({ - message: common.i18n.t('errors.api.posts.postNotFound') + return models.Post.destroy(opts).return(null) + .catch(models.Post.NotFoundError, function () { + throw new common.errors.NotFoundError({ + message: common.i18n.t('errors.api.posts.postNotFound') + }); }); - }); } // Push all of our tasks into a `tasks` array in the correct order