mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
52a855f314
refs https://github.com/TryGhost/Team/issues/1533 - Retrieves one newsletter - Makes the newsletter resource consistent with the other resources - Solves an issue with the admin expecting the route to exist
78 lines
1.7 KiB
JavaScript
78 lines
1.7 KiB
JavaScript
const models = require('../../models');
|
|
const tpl = require('@tryghost/tpl');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const messages = {
|
|
newsletterNotFound: 'Newsletter not found.'
|
|
};
|
|
|
|
module.exports = {
|
|
docName: 'newsletters',
|
|
|
|
browse: {
|
|
options: [
|
|
'filter',
|
|
'fields',
|
|
'limit',
|
|
'order',
|
|
'page'
|
|
],
|
|
permissions: true,
|
|
query(frame) {
|
|
return models.Newsletter.findPage(frame.options);
|
|
}
|
|
},
|
|
|
|
read: {
|
|
options: [
|
|
'fields',
|
|
'debug',
|
|
// NOTE: only for internal context
|
|
'forUpdate',
|
|
'transacting'
|
|
],
|
|
data: [
|
|
'id',
|
|
'slug',
|
|
'uuid'
|
|
],
|
|
permissions: true,
|
|
async query(frame) {
|
|
const newsletter = models.Newsletter.findOne(frame.data, frame.options);
|
|
|
|
if (!newsletter) {
|
|
throw new errors.NotFoundError({
|
|
message: tpl(messages.newsletterNotFound)
|
|
});
|
|
}
|
|
return newsletter;
|
|
}
|
|
},
|
|
|
|
add: {
|
|
statusCode: 201,
|
|
permissions: true,
|
|
async query(frame) {
|
|
return models.Newsletter.add(frame.data.newsletters[0], frame.options);
|
|
}
|
|
},
|
|
|
|
edit: {
|
|
headers: {},
|
|
options: [
|
|
'id'
|
|
],
|
|
validation: {
|
|
options: {
|
|
id: {
|
|
required: true
|
|
}
|
|
}
|
|
},
|
|
permissions: true,
|
|
async query(frame) {
|
|
return models.Newsletter.edit(frame.data.newsletters[0], frame.options);
|
|
}
|
|
}
|
|
};
|