Unify get catalog and tables middlewares
This commit is contained in:
parent
4df46fe5ea
commit
37111f396d
@ -17,8 +17,8 @@ AnalysesController.prototype.register = function (app) {
|
||||
userMiddleware,
|
||||
this.prepareContext,
|
||||
this.createPGClient(),
|
||||
this.getCatalog(),
|
||||
this.getTables(),
|
||||
this.getDataFromQuery({ queryTemplate: catalogQueryTpl, key: 'catalog' }),
|
||||
this.getDataFromQuery({ queryTemplate: tablesQueryTpl, key: 'tables' }),
|
||||
this.prepareResponse(),
|
||||
this.setCacheControlHeader(),
|
||||
this.sendResponse(),
|
||||
@ -33,36 +33,19 @@ AnalysesController.prototype.createPGClient = function () {
|
||||
};
|
||||
};
|
||||
|
||||
AnalysesController.prototype.getCatalog = function () {
|
||||
AnalysesController.prototype.getDataFromQuery = function ({ queryTemplate, key }) {
|
||||
const readOnlyTransactionOn = true;
|
||||
|
||||
return function getCatalogMiddleware(req, res, next) {
|
||||
const { pg, user } = res.locals;
|
||||
const catalogQuery = catalogQueryTpl({ _username: user });
|
||||
const readOnlyTransactionOn = true;
|
||||
const sql = queryTemplate({ _username: user });
|
||||
|
||||
pg.query(catalogQuery, (err, resultSet = {}) => {
|
||||
pg.query(sql, (err, resultSet = {}) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.locals.catalog = resultSet.rows || [];
|
||||
|
||||
next();
|
||||
}, readOnlyTransactionOn);
|
||||
};
|
||||
};
|
||||
|
||||
AnalysesController.prototype.getTables = function () {
|
||||
return function getTablesMiddleware(req, res, next) {
|
||||
const { pg, user } = res.locals;
|
||||
const tablesQuery = tablesQueryTpl({ _username: user });
|
||||
const readOnlyTransactionOn = true;
|
||||
|
||||
pg.query(tablesQuery, (err, resultSet = {}) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.locals.tables = resultSet.rows || [];
|
||||
res.locals[key] = resultSet.rows || [];
|
||||
|
||||
next();
|
||||
}, readOnlyTransactionOn);
|
||||
|
Loading…
Reference in New Issue
Block a user