2019-11-06 10:27:46 +03:00
|
|
|
const models = require('../../models');
|
2020-05-22 21:22:20 +03:00
|
|
|
const {i18n} = require('../../lib/common');
|
|
|
|
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',
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|