Add a single getter for all mail settings

This commit is contained in:
Girish Ramakrishnan
2018-01-20 22:56:45 -08:00
parent f93963540e
commit 3ed794e486
3 changed files with 27 additions and 92 deletions

View File

@@ -1,18 +1,13 @@
'use strict';
exports = module.exports = {
get: get,
getStatus: getStatus,
getMailFromValidation: getMailFromValidation,
setMailFromValidation: setMailFromValidation,
getCatchAllAddress: getCatchAllAddress,
setCatchAllAddress: setCatchAllAddress,
getMailRelay: getMailRelay,
setMailRelay: setMailRelay,
getMailConfig: getMailConfig,
setMailConfig: setMailConfig,
};
@@ -22,6 +17,17 @@ var assert = require('assert'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess;
function get(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');
mail.get(req.params.domain, function (error, result) {
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(200, result));
});
}
function getStatus(req, res, next) {
mail.getStatus(function (error, records) {
if (error) return next(new HttpError(500, error));
@@ -30,14 +36,6 @@ function getStatus(req, res, next) {
});
}
function getMailFromValidation(req, res, next) {
mail.getMailFromValidation(function (error, enabled) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, { enabled: enabled }));
});
}
function setMailFromValidation(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
@@ -51,14 +49,6 @@ function setMailFromValidation(req, res, next) {
});
}
function getCatchAllAddress(req, res, next) {
mail.getCatchAllAddress(function (error, address) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, { address: address }));
});
}
function setCatchAllAddress(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
@@ -76,14 +66,6 @@ function setCatchAllAddress(req, res, next) {
});
}
function getMailRelay(req, res, next) {
mail.getMailRelay(function (error, mail) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, mail));
});
}
function setMailRelay(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
@@ -101,14 +83,6 @@ function setMailRelay(req, res, next) {
});
}
function getMailConfig(req, res, next) {
mail.getMailConfig(function (error, mail) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, mail));
});
}
function setMailConfig(req, res, next) {
assert.strictEqual(typeof req.body, 'object');