diff --git a/core/server/api/canary/email-post.js b/core/server/api/canary/email-post.js new file mode 100644 index 0000000000..93ac1b4d46 --- /dev/null +++ b/core/server/api/canary/email-post.js @@ -0,0 +1,41 @@ +const i18n = require('../../../shared/i18n'); +const errors = require('@tryghost/errors'); +const models = require('../../models'); +const ALLOWED_INCLUDES = ['authors', 'tags']; + +module.exports = { + docName: 'email_post', + + read: { + permissions: true, + options: [ + 'include' + ], + data: [ + 'slug' + ], + validation: { + options: { + include: { + values: ALLOWED_INCLUDES + } + }, + data: { + slug: { + required: true + } + } + }, + async query(frame) { + const model = await models.Post.findOne(Object.assign(frame.data, {status: 'sent'}), frame.options); + + if (!model) { + throw new errors.NotFoundError({ + message: i18n.t('errors.api.posts.postNotFound') + }); + } + + return model; + } + } +}; diff --git a/core/server/api/canary/index.js b/core/server/api/canary/index.js index 4f987f31be..afed319b48 100644 --- a/core/server/api/canary/index.js +++ b/core/server/api/canary/index.js @@ -107,6 +107,10 @@ module.exports = { return shared.pipeline(require('./preview'), localUtils); }, + get emailPost() { + return shared.pipeline(require('./email-post'), localUtils); + }, + get oembed() { return shared.pipeline(require('./oembed'), localUtils); }, diff --git a/core/server/api/canary/utils/serializers/output/email-posts.js b/core/server/api/canary/utils/serializers/output/email-posts.js new file mode 100644 index 0000000000..e16125601e --- /dev/null +++ b/core/server/api/canary/utils/serializers/output/email-posts.js @@ -0,0 +1,13 @@ +const mapper = require('./utils/mapper'); +const gating = require('./utils/post-gating'); + +module.exports = { + read(model, apiConfig, frame) { + const emailPost = mapper.mapPost(model, frame); + gating.forPost(emailPost, frame); + + frame.response = { + email_posts: [emailPost] + }; + } +}; diff --git a/core/server/api/canary/utils/serializers/output/index.js b/core/server/api/canary/utils/serializers/output/index.js index 9a9e8f4275..df66f0752a 100644 --- a/core/server/api/canary/utils/serializers/output/index.js +++ b/core/server/api/canary/utils/serializers/output/index.js @@ -91,6 +91,10 @@ module.exports = { return require('./preview'); }, + get email_post() { + return require('./email-posts'); + }, + get oembed() { return require('./oembed'); },