2019-11-06 10:27:46 +03:00
|
|
|
const models = require('../../models');
|
2021-05-03 19:29:44 +03:00
|
|
|
const i18n = require('../../../shared/i18n');
|
2020-05-22 21:22:20 +03:00
|
|
|
const errors = require('@tryghost/errors');
|
2019-11-22 17:20:32 +03:00
|
|
|
const megaService = require('../../services/mega');
|
2019-11-06 10:27:46 +03:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
docName: 'emails',
|
|
|
|
|
2021-02-21 19:59:55 +03:00
|
|
|
browse: {
|
|
|
|
options: [
|
|
|
|
'limit',
|
|
|
|
'fields',
|
|
|
|
'filter',
|
|
|
|
'order',
|
|
|
|
'page'
|
|
|
|
],
|
|
|
|
permissions: true,
|
|
|
|
async query(frame) {
|
|
|
|
return await models.Email.findPage(frame.options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-06 10:27:46 +03:00
|
|
|
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) {
|
2020-05-22 21:22:20 +03:00
|
|
|
throw new errors.NotFoundError({
|
|
|
|
message: i18n.t('errors.models.email.emailNotFound')
|
2019-11-06 10:27:46 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-25 08:04:58 +03:00
|
|
|
return model;
|
2019-11-06 10:27:46 +03:00
|
|
|
});
|
|
|
|
}
|
2019-11-22 17:20:32 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
retry: {
|
|
|
|
data: [
|
|
|
|
'id'
|
|
|
|
],
|
|
|
|
permissions: true,
|
|
|
|
query(frame) {
|
|
|
|
return models.Email.findOne(frame.data, frame.options)
|
|
|
|
.then(async (model) => {
|
|
|
|
if (!model) {
|
2020-05-22 21:22:20 +03:00
|
|
|
throw new errors.NotFoundError({
|
|
|
|
message: i18n.t('errors.models.email.emailNotFound')
|
2019-11-22 17:20:32 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model.get('status') !== 'failed') {
|
2020-05-22 21:22:20 +03:00
|
|
|
throw new errors.IncorrectUsageError({
|
|
|
|
message: i18n.t('errors.models.email.retryNotAllowed')
|
2019-11-22 17:20:32 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-25 08:04:58 +03:00
|
|
|
return await megaService.mega.retryFailedEmail(model);
|
2019-11-22 17:20:32 +03:00
|
|
|
});
|
|
|
|
}
|
2019-11-06 10:27:46 +03:00
|
|
|
}
|
|
|
|
};
|