splitting behavior batch & not batch handling query

This commit is contained in:
Simon Martín 2019-02-26 17:09:36 +01:00
parent f925863534
commit b618691af9
2 changed files with 12 additions and 4 deletions

View File

@ -43,7 +43,7 @@ JobController.prototype.route = function (app) {
`${base_url}/sql/job`,
bodyParserMiddleware(),
checkBodyPayloadSize(),
handleQueryMiddleware(),
handleQueryMiddleware(true),
jobMiddlewares('create', createJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_CREATE)
);
app.get(

View File

@ -1,8 +1,16 @@
'use strict';
module.exports = function handleQuery () {
return function handleQueryMiddleware (req, res, next) {
res.locals.sql = (req.body && (req.body.q || req.body.query)) || (req.query && req.query.q);
module.exports = function handleQuery(isBatchAPIQuery = false) {
return function handleQueryMiddleware(req, res, next) {
res.locals.sql = isBatchAPIQuery ? batchApiQuery(req) : notBatchApiQuery(req);
return next();
};
};
function notBatchApiQuery(req) {
return (req.body && req.body.q) || (req.query && req.query.q);
}
function batchApiQuery(req) {
return req.body.query;
}