Make catalog method a regular middleware factory
This commit is contained in:
parent
5d6ccc07fd
commit
804c6645fa
@ -18,13 +18,39 @@ AnalysesController.prototype.register = function(app) {
|
||||
cors(),
|
||||
userMiddleware,
|
||||
this.prepareContext,
|
||||
this.catalog.bind(this),
|
||||
this.catalog(),
|
||||
this.prepareResponse(),
|
||||
this.setCacheControlHeader(),
|
||||
this.sendResponse()
|
||||
);
|
||||
};
|
||||
|
||||
AnalysesController.prototype.catalog = function () {
|
||||
return function catalogMiddleware(req, res, next) {
|
||||
const { user } = res.locals;
|
||||
|
||||
step(
|
||||
function catalogQuery() {
|
||||
var pg = new PSQL(dbParamsFromReqParams(res.locals));
|
||||
getMetadata(user, pg, this);
|
||||
},
|
||||
function prepareResponse(err, catalogWithTables) {
|
||||
if (err) {
|
||||
if (err.message.match(/permission\sdenied/)) {
|
||||
err = new Error('Unauthorized');
|
||||
err.http_status = 401;
|
||||
}
|
||||
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.locals.catalogWithTables = catalogWithTables;
|
||||
next();
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
AnalysesController.prototype.prepareResponse = function () {
|
||||
return function prepareResponseMiddleware (req, res, next) {
|
||||
const { catalogWithTables } = res.locals;
|
||||
@ -83,30 +109,6 @@ AnalysesController.prototype.sendResponse = function() {
|
||||
};
|
||||
};
|
||||
|
||||
AnalysesController.prototype.catalog = function (req, res, next) {
|
||||
var username = res.locals.user;
|
||||
|
||||
step(
|
||||
function catalogQuery() {
|
||||
var pg = new PSQL(dbParamsFromReqParams(res.locals));
|
||||
getMetadata(username, pg, this);
|
||||
},
|
||||
function prepareResponse(err, catalogWithTables) {
|
||||
if (err) {
|
||||
if (err.message.match(/permission\sdenied/)) {
|
||||
err = new Error('Unauthorized');
|
||||
err.http_status = 401;
|
||||
}
|
||||
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.locals.catalogWithTables = catalogWithTables;
|
||||
next();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var catalogQueryTpl = dot.template(
|
||||
'SELECT analysis_def->>\'type\' as type, * FROM cdb_analysis_catalog WHERE username = \'{{=it._username}}\''
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user