mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
0d7f253582
refs https://github.com/TryGhost/Team/issues/899 - The internal API is needed to be able to fetch email-only posts through email router. The concept is similar to Preview API with a difference that only posts with `sent` status are accessible and there is content-gating present.
42 lines
1000 B
JavaScript
42 lines
1000 B
JavaScript
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;
|
|
}
|
|
}
|
|
};
|