Added new browse email endpoint

refs https://github.com/TryGhost/Ghost/issues/12633

Adds new `browse` endpoint for emails that allows Admin to check performance of newsletters over time and show stats on dashboard as primary usecase
This commit is contained in:
Rish 2021-02-21 22:29:55 +05:30 committed by Rishabh Garg
parent 12a1c60424
commit 0620ff6ae0
3 changed files with 24 additions and 0 deletions

View File

@ -6,6 +6,20 @@ const megaService = require('../../services/mega');
module.exports = {
docName: 'emails',
browse: {
options: [
'limit',
'fields',
'filter',
'order',
'page'
],
permissions: true,
async query(frame) {
return await models.Email.findPage(frame.options);
}
},
read: {
options: [
'fields'

View File

@ -7,6 +7,15 @@ module.exports = {
};
},
browse(page, apiConfig, frame) {
const data = {
emails: page.data.map(model => mapper.mapEmail(model, frame)),
meta: page.meta
};
frame.response = data;
},
get retry() {
return this.read;
}

View File

@ -261,6 +261,7 @@ module.exports = function apiRoutes() {
router.post('/email_preview/posts/:id', mw.authAdminApi, http(apiCanary.email_preview.sendTestEmail));
// ## Emails
router.get('/emails', mw.authAdminApi, http(apiCanary.emails.browse));
router.get('/emails/:id', mw.authAdminApi, http(apiCanary.emails.read));
router.put('/emails/:id/retry', mw.authAdminApi, http(apiCanary.emails.retry));