mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
38b9cf2472
refs https://github.com/TryGhost/Team/issues/1571 refs https://ghost.slack.com/archives/C02G9E68C/p1650986988322609 - Makes sure the includes are always included - Moved read to the newsletter service - Added tests - Updated unit tests to work with multiple findOne calls - Fixed reject assertions not correctly awaiting in unit tests
115 lines
2.5 KiB
JavaScript
115 lines
2.5 KiB
JavaScript
const models = require('../../models');
|
|
const allowedIncludes = ['count.posts', 'count.members'];
|
|
|
|
const newslettersService = require('../../services/newsletters');
|
|
|
|
module.exports = {
|
|
docName: 'newsletters',
|
|
|
|
browse: {
|
|
options: [
|
|
'include',
|
|
'filter',
|
|
'fields',
|
|
'limit',
|
|
'order',
|
|
'page'
|
|
],
|
|
validation: {
|
|
options: {
|
|
include: {
|
|
values: allowedIncludes
|
|
}
|
|
}
|
|
},
|
|
permissions: true,
|
|
query(frame) {
|
|
return models.Newsletter.findPage(frame.options);
|
|
}
|
|
},
|
|
|
|
read: {
|
|
options: [
|
|
'include',
|
|
'fields',
|
|
'debug',
|
|
// NOTE: only for internal context
|
|
'forUpdate',
|
|
'transacting'
|
|
],
|
|
data: [
|
|
'id',
|
|
'slug',
|
|
'uuid'
|
|
],
|
|
validation: {
|
|
options: {
|
|
include: {
|
|
values: allowedIncludes
|
|
}
|
|
}
|
|
},
|
|
permissions: true,
|
|
async query(frame) {
|
|
return newslettersService.read(frame.data, frame.options);
|
|
}
|
|
},
|
|
|
|
add: {
|
|
statusCode: 201,
|
|
headers: {
|
|
cacheInvalidate: true
|
|
},
|
|
options: [
|
|
'include',
|
|
'opt_in_existing'
|
|
],
|
|
validation: {
|
|
options: {
|
|
include: {
|
|
values: allowedIncludes
|
|
}
|
|
}
|
|
},
|
|
permissions: true,
|
|
async query(frame) {
|
|
return newslettersService.add(frame.data.newsletters[0], frame.options);
|
|
}
|
|
},
|
|
|
|
edit: {
|
|
headers: {
|
|
cacheInvalidate: true
|
|
},
|
|
options: [
|
|
'id',
|
|
'include'
|
|
],
|
|
validation: {
|
|
options: {
|
|
id: {
|
|
required: true
|
|
},
|
|
include: {
|
|
values: allowedIncludes
|
|
}
|
|
}
|
|
},
|
|
permissions: true,
|
|
async query(frame) {
|
|
return newslettersService.edit(frame.data.newsletters[0], frame.options);
|
|
}
|
|
},
|
|
|
|
verifyPropertyUpdate: {
|
|
permissions: {
|
|
method: 'edit'
|
|
},
|
|
data: [
|
|
'token'
|
|
],
|
|
async query(frame) {
|
|
return newslettersService.verifyPropertyUpdate(frame.data.token);
|
|
}
|
|
}
|
|
};
|