2021-10-04 11:57:08 +03:00
|
|
|
const tpl = require('@tryghost/tpl');
|
2021-08-13 09:12:54 +03:00
|
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const models = require('../../models');
|
|
|
|
const ALLOWED_INCLUDES = ['authors', 'tags'];
|
|
|
|
|
2021-10-04 11:57:08 +03:00
|
|
|
const messages = {
|
|
|
|
postNotFound: 'Post not found.'
|
|
|
|
};
|
|
|
|
|
2021-08-13 09:12:54 +03:00
|
|
|
module.exports = {
|
|
|
|
docName: 'email_post',
|
|
|
|
|
|
|
|
read: {
|
|
|
|
permissions: true,
|
|
|
|
options: [
|
|
|
|
'include'
|
|
|
|
],
|
|
|
|
data: [
|
2021-08-19 11:27:45 +03:00
|
|
|
'uuid'
|
2021-08-13 09:12:54 +03:00
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
include: {
|
|
|
|
values: ALLOWED_INCLUDES
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data: {
|
2021-08-19 11:27:45 +03:00
|
|
|
uuid: {
|
2021-08-13 09:12:54 +03:00
|
|
|
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({
|
2021-10-04 11:57:08 +03:00
|
|
|
message: tpl(messages.postNotFound)
|
2021-08-13 09:12:54 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|