3b6cdc2bc5
refs https://github.com/TryGhost/Toolbox/issues/308 - we have a pattern of using plurals around Ghost but this was singular - this shouldn't change any API functionality, it's just code refactoring
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
const tpl = require('@tryghost/tpl');
|
|
const errors = require('@tryghost/errors');
|
|
const models = require('../../models');
|
|
const ALLOWED_INCLUDES = ['authors', 'tags'];
|
|
|
|
const messages = {
|
|
postNotFound: 'Post not found.'
|
|
};
|
|
|
|
module.exports = {
|
|
docName: 'previews',
|
|
|
|
read: {
|
|
permissions: true,
|
|
options: [
|
|
'include'
|
|
],
|
|
data: [
|
|
'uuid'
|
|
],
|
|
validation: {
|
|
options: {
|
|
include: {
|
|
values: ALLOWED_INCLUDES
|
|
}
|
|
},
|
|
data: {
|
|
uuid: {
|
|
required: true
|
|
}
|
|
}
|
|
},
|
|
query(frame) {
|
|
return models.Post.findOne(Object.assign({status: 'all'}, frame.data), frame.options)
|
|
.then((model) => {
|
|
if (!model) {
|
|
throw new errors.NotFoundError({
|
|
message: tpl(messages.postNotFound)
|
|
});
|
|
}
|
|
|
|
return model;
|
|
});
|
|
}
|
|
}
|
|
};
|