mailboxdb: merge into mail.js
This commit is contained in:
@@ -4,8 +4,8 @@ exports = module.exports = {
|
||||
proxy,
|
||||
restart,
|
||||
|
||||
getLocation,
|
||||
setLocation
|
||||
setLocation,
|
||||
getLocation
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
@@ -16,6 +16,7 @@ const assert = require('assert'),
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
mail = require('../mail.js'),
|
||||
middleware = require('../middleware/index.js'),
|
||||
safe = require('safetydance'),
|
||||
services = require('../services.js'),
|
||||
url = require('url');
|
||||
|
||||
@@ -55,23 +56,21 @@ function proxy(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
function getLocation(req, res, next) {
|
||||
mail.getLocation(function (error, result) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
async function getLocation(req, res, next) {
|
||||
const [error, result] = await safe(mail.getLocation());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { domain: result.domain, subdomain: result.subdomain }));
|
||||
});
|
||||
next(new HttpSuccess(200, { domain: result.domain, subdomain: result.subdomain }));
|
||||
}
|
||||
|
||||
function setLocation(req, res, next) {
|
||||
async function setLocation(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
||||
if (typeof req.body.subdomain !== 'string') return next(new HttpError(400, 'subdomain must be a string'));
|
||||
|
||||
mail.setLocation(req.body.subdomain, req.body.domain, auditSource.fromRequest(req), function (error, taskId) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error, taskId] = await safe(mail.setLocation(req.body.subdomain, req.body.domain, auditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
});
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
}
|
||||
Reference in New Issue
Block a user