refactoring copy controller middlewares
This commit is contained in:
parent
433bd01c27
commit
f01191472b
@ -34,8 +34,8 @@ CopyController.prototype.route = function (app) {
|
||||
authorizationMiddleware(this.metadataBackend),
|
||||
connectionParamsMiddleware(this.userDatabaseService),
|
||||
timeoutLimitsMiddleware(this.metadataBackend),
|
||||
this.handleCopyFrom.bind(this),
|
||||
this.responseCopyFrom.bind(this),
|
||||
handleCopyFrom(),
|
||||
responseCopyFrom(),
|
||||
errorMiddleware()
|
||||
];
|
||||
};
|
||||
@ -106,7 +106,8 @@ function handleCopyTo (statsClient) {
|
||||
};
|
||||
}
|
||||
|
||||
CopyController.prototype.handleCopyFrom = function (req, res, next) {
|
||||
function handleCopyFrom () {
|
||||
return function handleCopyFromMiddleware (req, res, next) {
|
||||
const { sql } = req.query;
|
||||
|
||||
if (!sql) {
|
||||
@ -158,10 +159,11 @@ CopyController.prototype.handleCopyFrom = function (req, res, next) {
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CopyController.prototype.responseCopyFrom = function (req, res, next) {
|
||||
function responseCopyFrom () {
|
||||
return function responseCopyFromMiddleware (req, res, next) {
|
||||
if (!res.body || !res.body.total_rows) {
|
||||
return next(new Error("No rows copied"));
|
||||
}
|
||||
@ -180,6 +182,7 @@ CopyController.prototype.responseCopyFrom = function (req, res, next) {
|
||||
}
|
||||
|
||||
res.send(res.body);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = CopyController;
|
||||
|
Loading…
Reference in New Issue
Block a user