2019-02-26 21:36:11 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-02-27 00:09:36 +08:00
|
|
|
module.exports = function handleQuery(isBatchAPIQuery = false) {
|
|
|
|
return function handleQueryMiddleware(req, res, next) {
|
|
|
|
res.locals.sql = isBatchAPIQuery ? batchApiQuery(req) : notBatchApiQuery(req);
|
2019-02-26 21:36:11 +08:00
|
|
|
return next();
|
|
|
|
};
|
|
|
|
};
|
2019-02-27 00:09:36 +08:00
|
|
|
|
|
|
|
function notBatchApiQuery(req) {
|
|
|
|
return (req.body && req.body.q) || (req.query && req.query.q);
|
|
|
|
}
|
|
|
|
|
|
|
|
function batchApiQuery(req) {
|
2019-02-27 00:11:11 +08:00
|
|
|
return req.body && req.body.query;
|
2019-02-27 00:09:36 +08:00
|
|
|
}
|