2015-12-10 03:17:45 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function UserDatabaseMetadataService(metadataBackend) {
|
|
|
|
this.metadataBackend = metadataBackend;
|
|
|
|
}
|
|
|
|
|
|
|
|
UserDatabaseMetadataService.prototype.getUserMetadata = function (username, callback) {
|
2015-12-11 01:09:43 +08:00
|
|
|
var self = this;
|
|
|
|
|
2015-12-10 03:17:45 +08:00
|
|
|
this.metadataBackend.getAllUserDBParams(username, function (err, userDatabaseMetadata) {
|
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
2015-12-30 18:51:32 +08:00
|
|
|
callback(null, self.parseMetadataToDatabase(userDatabaseMetadata));
|
2015-12-10 03:17:45 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-12-30 18:51:32 +08:00
|
|
|
UserDatabaseMetadataService.prototype.parseMetadataToDatabase = function (userDatabaseMetadata) {
|
2015-12-11 01:09:43 +08:00
|
|
|
var dbParams = userDatabaseMetadata;
|
|
|
|
|
2016-01-14 21:08:34 +08:00
|
|
|
var dbopts = {};
|
2015-12-11 01:09:43 +08:00
|
|
|
|
2016-01-14 21:08:34 +08:00
|
|
|
dbopts.port = dbParams.dbport || global.settings.db_batch_port || global.settings.db_port;
|
2015-12-11 01:09:43 +08:00
|
|
|
dbopts.host = dbParams.dbhost;
|
|
|
|
dbopts.dbname = dbParams.dbname;
|
|
|
|
|
|
|
|
return dbopts;
|
|
|
|
};
|
|
|
|
|
2015-12-10 03:17:45 +08:00
|
|
|
module.exports = UserDatabaseMetadataService;
|