Mail-Queue management in admin panel.
This commit is contained in:
parent
807f3f5fb2
commit
26aaec385a
8 changed files with 376 additions and 3 deletions
server/resources
101
server/resources/mailResource.js
Normal file
101
server/resources/mailResource.js
Normal file
|
@ -0,0 +1,101 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng').factory('MailResource', function (
|
||||
Constraints,
|
||||
Validator,
|
||||
MailService,
|
||||
Resources,
|
||||
Logger,
|
||||
ErrorTypes,
|
||||
Strings
|
||||
) {
|
||||
var isValidId = Validator.forConstraint(Constraints.id);
|
||||
|
||||
function withValidMailId(req, res, callback) {
|
||||
var id = Strings.normalizeString(Resources.getData(req).id);
|
||||
|
||||
if (!isValidId(id)) {
|
||||
return callback({data: 'Invalid mail id.', type: ErrorTypes.badRequest});
|
||||
}
|
||||
|
||||
callback(null, id);
|
||||
}
|
||||
|
||||
return {
|
||||
get: function (req, res) {
|
||||
withValidMailId(req, res, function (err, id) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
|
||||
MailService.getMail(id, function (err, mail) {
|
||||
if (err) {
|
||||
Logger.tag('mails', 'admin').error('Error getting mail:', err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
|
||||
if (!mail) {
|
||||
return Resources.error(res, {data: 'Mail not found.', type: ErrorTypes.notFound});
|
||||
}
|
||||
|
||||
return Resources.success(res, mail);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getAll: function (req, res) {
|
||||
Resources.getValidRestParams('list', req, function (err, restParams) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
|
||||
return MailService.getPendingMails(
|
||||
restParams,
|
||||
function (err, mails, total) {
|
||||
if (err) {
|
||||
Logger.tag('mails', 'admin').error('Could not get pending mails:', err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
|
||||
res.set('X-Total-Count', total);
|
||||
return Resources.success(res, mails);
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
delete: function (req, res) {
|
||||
withValidMailId(req, res, function (err, id) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
|
||||
MailService.deleteMail(id, function (err) {
|
||||
if (err) {
|
||||
Logger.tag('mails', 'admin').error('Error deleting mail:', err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
|
||||
return Resources.success(res);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
resetFailures: function (req, res) {
|
||||
withValidMailId(req, res, function (err, id) {
|
||||
if (err) {
|
||||
return Resources.error(res, err);
|
||||
}
|
||||
|
||||
MailService.resetFailures(id, function (err, mail) {
|
||||
if (err) {
|
||||
Logger.tag('mails', 'admin').error('Error resetting failure count:', err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
|
||||
return Resources.success(res, mail);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue