From e64274bb45e948c52d6fbac564f609a24e33ce6e Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 5 Aug 2021 14:13:02 +0400 Subject: [PATCH] Refactored Posts API v2 controller refs https://github.com/TryGhost/Team/issues/949 - This refactor is needed to bring the code in line with the rest of post API controllers - Next step will extract shared code patterns into a separate module --- core/server/api/v2/posts.js | 43 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/core/server/api/v2/posts.js b/core/server/api/v2/posts.js index a628080af3..ee659b8f51 100644 --- a/core/server/api/v2/posts.js +++ b/core/server/api/v2/posts.js @@ -140,29 +140,28 @@ module.exports = { permissions: { unsafeAttrs: unsafeAttrs }, - query(frame) { - return models.Post.edit(frame.data.posts[0], frame.options) - .then((model) => { - if ( - model.get('status') === 'published' && model.wasChanged() || - model.get('status') === 'draft' && model.previous('status') === 'published' - ) { - this.headers.cacheInvalidate = true; - } else if ( - model.get('status') === 'draft' && model.previous('status') !== 'published' || - model.get('status') === 'scheduled' && model.wasChanged() - ) { - this.headers.cacheInvalidate = { - value: urlUtils.urlFor({ - relativeUrl: urlUtils.urlJoin('/p', model.get('uuid'), '/') - }) - }; - } else { - this.headers.cacheInvalidate = false; - } + async query(frame) { + const model = await models.Post.edit(frame.data.posts[0], frame.options) - return model; - }); + if ( + model.get('status') === 'published' && model.wasChanged() || + model.get('status') === 'draft' && model.previous('status') === 'published' + ) { + this.headers.cacheInvalidate = true; + } else if ( + model.get('status') === 'draft' && model.previous('status') !== 'published' || + model.get('status') === 'scheduled' && model.wasChanged() + ) { + this.headers.cacheInvalidate = { + value: urlUtils.urlFor({ + relativeUrl: urlUtils.urlJoin('/p', model.get('uuid'), '/') + }) + }; + } else { + this.headers.cacheInvalidate = false; + } + + return model; } },