Ghost/core/server/api/canary/email.js

61 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-11-06 10:27:46 +03:00
const models = require('../../models');
const common = require('../../lib/common');
const megaService = require('../../services/mega');
2019-11-06 10:27:46 +03:00
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.models.email.emailNotFound')
2019-11-06 10:27:46 +03:00
});
}
return model.toJSON(frame.options);
});
}
},
retry: {
data: [
'id'
],
permissions: true,
query(frame) {
return models.Email.findOne(frame.data, frame.options)
.then(async (model) => {
if (!model) {
throw new common.errors.NotFoundError({
message: common.i18n.t('errors.models.email.emailNotFound')
});
}
if (model.get('status') !== 'failed') {
throw new common.errors.IncorrectUsageError({
message: common.i18n.t('errors.models.email.retryNotAllowed')
});
}
const result = await megaService.mega.retryFailedEmail(model);
return result.toJSON(frame.options);
});
}
2019-11-06 10:27:46 +03:00
}
};