add routes to create and delete mail domain

This commit is contained in:
Girish Ramakrishnan
2018-01-24 21:15:58 -08:00
committed by Johannes Zellner
parent ef3ab44199
commit b71c0bde55
3 changed files with 56 additions and 0 deletions

View File

@@ -3,6 +3,9 @@
exports = module.exports = {
get: get,
add: add,
del: del,
getStatus: getStatus,
setMailFromValidation: setMailFromValidation,
@@ -35,6 +38,29 @@ function get(req, res, next) {
});
}
function add(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');
mail.add(req.params.domain, function (error, result) {
if (error && error.reason === MailError.NOT_FOUND) return next(new HttpError(404, error.message));
if (error && error.reason === MailError.ALREADY_EXISTS) return next(new HttpError(400, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, result));
});
}
function del(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');
mail.del(req.params.domain, function (error) {
if (error && error.reason === MailError.NOT_FOUND) return next(new HttpError(404, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(202, { }));
});
}
function getStatus(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');