move dashboard change routes under dashboard/

This commit is contained in:
Girish Ramakrishnan
2023-08-13 10:06:01 +05:30
parent 7b32cb16f3
commit e723c3c19b
9 changed files with 134 additions and 135 deletions
+24 -1
View File
@@ -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, {}));
}