Commit ce94a13d by Chavee Issariyapat

use group _key as a groupid instead of group name

parent 78146367
var config = require('config');
var seneca = require('seneca')({log: 'silent'}).client({ port: config.get('device_registry_port'), host: config.get('device_registry_host') });
var getRole = require('../checkClientRole').getRole var getRole = require('../checkClientRole').getRole
function getGroupID(token, client_id) { async function getGroupID(token, client_id) {
var role = getRole(token) var role = getRole(token);
if (role) { if (role && role.hasOwnProperty('groupId')) {
if (role.hasOwnProperty('groupId')) { return role.groupId;
return role.groupId
} }
else { else {
return doDB(client_id) var group = await doDB(client_id);
} return group;
} }
else return role
} }
module.exports.getGroupID = getGroupID module.exports.getGroupID = getGroupID
function doDB(client_id) { function doDB(client_id) {
var groupId = 'test' return new Promise((resolve, reject) => {
return groupId seneca.act('cmd:getGroupByClientid, clientid:'+client_id, function(err, res) {
if (err) reject(err);
else resolve((res && res.result &&res.result[0])?res.result[0]:null);
});
});
}
//Test
async function test() {
var g = await getGroupID('', 'aw9f0d2c-aliceclient');
console.log(g);
} }
test();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment