diff --git a/core/server/api/canary/email-preview.js b/core/server/api/canary/email-preview.js new file mode 100644 index 0000000000..0dbc70a8d2 --- /dev/null +++ b/core/server/api/canary/email-preview.js @@ -0,0 +1,36 @@ +const models = require('../../models'); +const common = require('../../lib/common'); +const mega = require('../../services/mega'); + +module.exports = { + docName: 'email_preview', + + read: { + options: [ + 'fields' + ], + validation: { + options: { + fields: ['html', 'plaintext', 'subject'] + } + }, + data: [ + 'id' + ], + permissions: true, + query(frame) { + return models.Post.findOne(frame.data, frame.options) + .then((model) => { + if (!model) { + throw new common.errors.NotFoundError({ + message: common.i18n.t('errors.api.posts.postNotFound') + }); + } + + const post = model.toJSON(); + + return mega.postEmailSerializer.serialize(post); + }); + } + } +};