move dashboard change routes under dashboard/
This commit is contained in:
+24
-1
@@ -2,10 +2,15 @@
|
||||
|
||||
exports = module.exports = {
|
||||
getConfig,
|
||||
|
||||
prepareDomain,
|
||||
switchDomain
|
||||
};
|
||||
|
||||
const BoxError = require('../boxerror.js'),
|
||||
const AuditSource = require('../auditsource.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
dashboard = require('../dashboard.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
safe = require('safetydance');
|
||||
|
||||
@@ -15,3 +20,21 @@ async function getConfig(req, res, next) {
|
||||
|
||||
next(new HttpSuccess(200, cloudronConfig));
|
||||
}
|
||||
|
||||
async function prepareDomain(req, res, next) {
|
||||
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
||||
|
||||
const [error, taskId] = await safe(dashboard.prepareDomain(req.body.domain, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
}
|
||||
|
||||
async function switchDomain(req, res, next) {
|
||||
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
||||
|
||||
const [error] = await safe(dashboard.switchDomain(req.body.domain, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user