2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Implemented GET /emails/:id endpoint

This commit is contained in:
Nazar Gargol 2019-11-06 14:27:46 +07:00 committed by Naz Gargol
parent 1ed2598c3b
commit ae14eb00f9
6 changed files with 55 additions and 1 deletions

View file

@ -0,0 +1,33 @@
const models = require('../../models');
const common = require('../../lib/common');
module.exports = {
docName: 'emails',
read: {
options: [
'fields'
],
validation: {
options: {
fields: ['html', 'plaintext', 'subject']
}
},
data: [
'id'
],
permissions: true,
query(frame) {
return models.Email.findOne(frame.data, frame.options)
.then((model) => {
if (!model) {
throw new common.errors.NotFoundError({
message: common.i18n.t('errors.api.email.emailNotFound')
});
}
return model.toJSON(frame.options);
});
}
}
};

View file

@ -111,6 +111,10 @@ module.exports = {
return shared.pipeline(require('./email-preview'), localUtils);
},
get emails() {
return shared.pipeline(require('./email'), localUtils);
},
get site() {
return shared.pipeline(require('./site'), localUtils);
},

View file

@ -0,0 +1,7 @@
module.exports = {
read(email, apiConfig, frame) {
frame.response = {
emails: [email]
};
}
};

View file

@ -105,5 +105,9 @@ module.exports = {
get email_preview() {
return require('./email-preview');
},
get emails() {
return require('./emails');
}
};

View file

@ -255,6 +255,9 @@
"api_key": {
"apiKeyNotFound": "API Key not found"
},
"email": {
"emailNotFound": "Email not found."
},
"base": {
"index": {
"missingContext": "missing context"

View file

@ -215,9 +215,12 @@ module.exports = function apiRoutes() {
// ## Actions
router.get('/actions', mw.authAdminApi, http(apiCanary.actions.browse));
// ## Emails
// ## Email Preview
router.get('/email_preview/posts/:id', mw.authAdminApi, http(apiCanary.email_preview.read));
router.post('/email_preview/posts/:id', mw.authAdminApi, http(apiCanary.email_preview.sendTestEmail));
// ## Emails
router.get('/emails/:id', mw.authAdminApi, http(apiCanary.emails.read));
return router;
};