2022-03-28 18:24:51 +03:00
|
|
|
const models = require('../../models');
|
2022-04-21 10:59:44 +03:00
|
|
|
const tpl = require('@tryghost/tpl');
|
|
|
|
const errors = require('@tryghost/errors');
|
|
|
|
|
|
|
|
const messages = {
|
|
|
|
newsletterNotFound: 'Newsletter not found.'
|
|
|
|
};
|
2022-03-28 18:24:51 +03:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
docName: 'newsletters',
|
|
|
|
|
|
|
|
browse: {
|
|
|
|
options: [
|
|
|
|
'filter',
|
|
|
|
'fields',
|
|
|
|
'limit',
|
|
|
|
'order',
|
|
|
|
'page'
|
|
|
|
],
|
|
|
|
permissions: true,
|
|
|
|
query(frame) {
|
|
|
|
return models.Newsletter.findPage(frame.options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-04-21 10:59:44 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-03-28 18:24:51 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|