Use ES6 class syntax in Copy from/to controller

This commit is contained in:
Daniel García Aubert 2019-10-01 12:31:05 +02:00
parent 6c775c1857
commit d85331e97b

View File

@ -17,47 +17,49 @@ const { PassThrough } = require('stream');
const params = require('../middlewares/params'); const params = require('../middlewares/params');
const bodyParserMiddleware = require('../middlewares/body-parser'); const bodyParserMiddleware = require('../middlewares/body-parser');
function CopyController(metadataBackend, userDatabaseService, userLimitsService, logger) { module.exports = class CopyController {
this.metadataBackend = metadataBackend; constructor (metadataBackend, userDatabaseService, userLimitsService, logger) {
this.userDatabaseService = userDatabaseService; this.metadataBackend = metadataBackend;
this.userLimitsService = userLimitsService; this.userDatabaseService = userDatabaseService;
this.logger = logger; this.userLimitsService = userLimitsService;
} this.logger = logger;
}
CopyController.prototype.route = function (apiRouter) { route (apiRouter) {
const copyFromMiddlewares = endpointGroup => { const copyFromMiddlewares = endpointGroup => {
return [ return [
initializeProfilerMiddleware('copyfrom'), initializeProfilerMiddleware('copyfrom'),
userMiddleware(this.metadataBackend), userMiddleware(this.metadataBackend),
rateLimitsMiddleware(this.userLimitsService, endpointGroup), rateLimitsMiddleware(this.userLimitsService, endpointGroup),
authorizationMiddleware(this.metadataBackend), authorizationMiddleware(this.metadataBackend),
connectionParamsMiddleware(this.userDatabaseService), connectionParamsMiddleware(this.userDatabaseService),
dbQuotaMiddleware(), dbQuotaMiddleware(),
params({ strategy: 'copyfrom' }), params({ strategy: 'copyfrom' }),
handleCopyFrom(this.logger), handleCopyFrom(this.logger),
errorHandler(this.logger), errorHandler(this.logger),
errorMiddleware() errorMiddleware()
]; ];
}; };
const copyToMiddlewares = endpointGroup => { const copyToMiddlewares = endpointGroup => {
return [ return [
bodyParserMiddleware(), bodyParserMiddleware(),
initializeProfilerMiddleware('copyto'), initializeProfilerMiddleware('copyto'),
userMiddleware(this.metadataBackend), userMiddleware(this.metadataBackend),
rateLimitsMiddleware(this.userLimitsService, endpointGroup), rateLimitsMiddleware(this.userLimitsService, endpointGroup),
authorizationMiddleware(this.metadataBackend), authorizationMiddleware(this.metadataBackend),
connectionParamsMiddleware(this.userDatabaseService), connectionParamsMiddleware(this.userDatabaseService),
params({ strategy: 'copyto' }), params({ strategy: 'copyto' }),
handleCopyTo(this.logger), handleCopyTo(this.logger),
errorHandler(this.logger), errorHandler(this.logger),
errorMiddleware() errorMiddleware()
]; ];
}; };
apiRouter.post('/sql/copyfrom', copyFromMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_FROM)); apiRouter.post('/sql/copyfrom', copyFromMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_FROM));
apiRouter.get('/sql/copyto', copyToMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_TO)); apiRouter.get('/sql/copyto', copyToMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_TO));
apiRouter.post('/sql/copyto', copyToMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_TO)); apiRouter.post('/sql/copyto', copyToMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.COPY_TO));
}
}; };
function handleCopyTo (logger) { function handleCopyTo (logger) {
@ -178,5 +180,3 @@ function errorHandler (logger) {
} }
}; };
} }
module.exports = CopyController;