using handleQueryMiddleware in query controller

This commit is contained in:
Simon Martín 2019-02-26 14:47:23 +01:00
parent 143af82b8b
commit 69e2aaf748

View File

@ -20,6 +20,7 @@ const timeoutLimitsMiddleware = require('../middlewares/timeout-limits');
const { initializeProfilerMiddleware } = require('../middlewares/profiler'); const { initializeProfilerMiddleware } = require('../middlewares/profiler');
const rateLimitsMiddleware = require('../middlewares/rate-limit'); const rateLimitsMiddleware = require('../middlewares/rate-limit');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitsMiddleware; const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitsMiddleware;
const handleQueryMiddleware = require('../middlewares/handle-query');
var ONE_YEAR_IN_SECONDS = 31536000; // 1 year time to live by default var ONE_YEAR_IN_SECONDS = 31536000; // 1 year time to live by default
@ -44,6 +45,7 @@ QueryController.prototype.route = function (app) {
authorizationMiddleware(this.metadataBackend, forceToBeMaster), authorizationMiddleware(this.metadataBackend, forceToBeMaster),
connectionParamsMiddleware(this.userDatabaseService), connectionParamsMiddleware(this.userDatabaseService),
timeoutLimitsMiddleware(this.metadataBackend), timeoutLimitsMiddleware(this.metadataBackend),
handleQueryMiddleware(),
this.handleQuery.bind(this), this.handleQuery.bind(this),
errorMiddleware() errorMiddleware()
]; ];
@ -56,11 +58,9 @@ QueryController.prototype.route = function (app) {
// jshint maxcomplexity:21 // jshint maxcomplexity:21
QueryController.prototype.handleQuery = function (req, res, next) { QueryController.prototype.handleQuery = function (req, res, next) {
var self = this; var self = this;
// extract input var sql = res.locals.q;
var body = (req.body) ? req.body : {};
// clone so don't modify req.params or req.body so oauth is not broken // clone so don't modify req.params or req.body so oauth is not broken
var params = _.extend({}, req.query, body); var params = _.extend({}, req.query, req.body || {});
var sql = params.q;
var limit = parseInt(params.rows_per_page); var limit = parseInt(params.rows_per_page);
var offset = parseInt(params.page); var offset = parseInt(params.page);
var orderBy = params.order_by; var orderBy = params.order_by;