2019-11-06 10:27:46 +03:00
|
|
|
const models = require('../../models');
|
|
|
|
const common = require('../../lib/common');
|
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) {
|
|
|
|
throw new common.errors.NotFoundError({
|
2019-11-22 17:20:32 +03:00
|
|
|
message: common.i18n.t('errors.models.email.emailNotFound')
|
2019-11-06 10:27:46 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return model.toJSON(frame.options);
|
|
|
|
});
|
|
|
|
}
|
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) {
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|