2018-02-22 19:22:39 +08:00
|
|
|
module.exports = function connectionParams (userDatabaseService) {
|
|
|
|
return function connectionParamsMiddleware (req, res, next) {
|
2018-06-05 19:21:56 +08:00
|
|
|
const { user, api_key: apikeyToken, authorizationLevel } = res.locals;
|
2018-02-22 19:22:39 +08:00
|
|
|
|
2018-06-05 19:21:56 +08:00
|
|
|
userDatabaseService.getConnectionParams(user, apikeyToken, authorizationLevel,
|
2018-02-22 22:59:13 +08:00
|
|
|
function (err, userDbParams, authDbParams) {
|
2018-02-22 19:22:39 +08:00
|
|
|
if (req.profiler) {
|
2018-02-22 19:23:37 +08:00
|
|
|
req.profiler.done('getConnectionParams');
|
2018-02-22 19:22:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.userDbParams = userDbParams;
|
|
|
|
res.locals.authDbParams = authDbParams;
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|