2019-11-05 08:14:26 +03:00
|
|
|
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: [
|
2019-11-06 07:57:46 +03:00
|
|
|
'id',
|
|
|
|
'status'
|
2019-11-05 08:14:26 +03:00
|
|
|
],
|
|
|
|
permissions: true,
|
|
|
|
query(frame) {
|
2019-11-05 11:04:48 +03:00
|
|
|
const options = Object.assign(frame.options, {formats: 'html,plaintext'});
|
|
|
|
return models.Post.findOne(frame.data, options)
|
2019-11-05 08:14:26 +03:00
|
|
|
.then((model) => {
|
|
|
|
if (!model) {
|
|
|
|
throw new common.errors.NotFoundError({
|
|
|
|
message: common.i18n.t('errors.api.posts.postNotFound')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-05 11:04:48 +03:00
|
|
|
const post = model.toJSON(options);
|
2019-11-05 08:14:26 +03:00
|
|
|
|
|
|
|
return mega.postEmailSerializer.serialize(post);
|
|
|
|
});
|
|
|
|
}
|
2019-11-05 12:09:07 +03:00
|
|
|
},
|
|
|
|
sendTestEmail: {
|
|
|
|
statusCode: 200,
|
|
|
|
headers: {},
|
|
|
|
options: [
|
|
|
|
'id'
|
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
id: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
permissions: false,
|
|
|
|
async query(frame) {
|
|
|
|
let model = await models.Post.findOne(frame.options);
|
|
|
|
if (!model) {
|
|
|
|
throw new common.errors.NotFoundError({
|
|
|
|
message: common.i18n.t('errors.api.posts.postNotFound')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const post = model.toJSON();
|
|
|
|
const {emails = []} = frame.data;
|
|
|
|
return mega.mega.sendTestEmail(post, emails);
|
|
|
|
}
|
2019-11-05 08:14:26 +03:00
|
|
|
}
|
|
|
|
};
|