Commit e247d158 by Chavee Issariyapat

clean up code

parent aea22f6e
...@@ -43,6 +43,7 @@ module.exports = function (options = {}) { ...@@ -43,6 +43,7 @@ module.exports = function (options = {}) {
var GGID = require('./utils/getGroupID'); var GGID = require('./utils/getGroupID');
GGID.getGroupID(req.body.username, req.body.client_id, function (group) { GGID.getGroupID(req.body.username, req.body.client_id, function (group) {
if (group) { if (group) {
var _ftopic = require('./utils/router').rewriteTopic(topic, 'sub', group, req.body.client_id) // get topic where concat with groupID var _ftopic = require('./utils/router').rewriteTopic(topic, 'sub', group, req.body.client_id) // get topic where concat with groupID
var _topic = [{ // setTopic for response var _topic = [{ // setTopic for response
......
...@@ -11,9 +11,9 @@ function getGroupID(token, client_id, callback) { ...@@ -11,9 +11,9 @@ function getGroupID(token, client_id, callback) {
callback(role.groupId); callback(role.groupId);
} }
else { else {
doDB(client_id, function(group) { doDB(client_id, function(groupid) {
if (group) callback(group); if (groupid) callback(groupid);
else callback(client_id); // fake group to isolate device else callback(client_id); // fake group to isolate device
}); });
...@@ -22,6 +22,7 @@ function getGroupID(token, client_id, callback) { ...@@ -22,6 +22,7 @@ function getGroupID(token, client_id, callback) {
function doDB(client_id, callback) { function doDB(client_id, callback) {
seneca.act('cmd:getGroupByClientid, clientid:'+client_id, function(err, res) { seneca.act('cmd:getGroupByClientid, clientid:'+client_id, function(err, res) {
if (err) callback(null); if (err) callback(null);
else callback((res && res.result &&res.result[0])?res.result[0]:null); else callback((res && res.result &&res.result[0])?res.result[0]:null);
}); });
......
...@@ -15,6 +15,7 @@ function rewriteTopic(topic, op, groupid, clientid, output) { ...@@ -15,6 +15,7 @@ function rewriteTopic(topic, op, groupid, clientid, output) {
return modify.insertWordIntoTopic(topic, '!'+clientid, 3); return modify.insertWordIntoTopic(topic, '!'+clientid, 3);
} }
else if ( chunk[2].startsWith('updated:')) { else if ( chunk[2].startsWith('updated:')) {
return modify.insertWordIntoTopic(topic, '!'+groupid, 3); return modify.insertWordIntoTopic(topic, '!'+groupid, 3);
} }
else { else {
...@@ -37,36 +38,8 @@ function rewriteTopic(topic, op, groupid, clientid, output) { ...@@ -37,36 +38,8 @@ function rewriteTopic(topic, op, groupid, clientid, output) {
} }
break; break;
// if (chunk[1] == 'set' || chunk[1] == 'overset' || chunk[1] == 'get') {
// output.verb = chunk[1];
// return modify.insertWordIntoTopic(topic, ''+clientid, 2);
// }
// else if (chunk[1] == 'write' || chunk[1] == 'overwrite' || chunk[1] == 'read') {
// output.verb = chunk[1];
// return modify.insertWordIntoTopic(topic, groupid, 2);
// }
// else if (chunk[1] == 'changed') {
// if (op == 'pub') {
// if ( chunk.length > 2 )
// return modify.insertWordIntoTopic(topic, '!'+groupid, 2);
// else if ( chunk.length == 2 )
// return modify.insertWordIntoTopic(topic, '!'+clientid, 2);
// else return "";
// }
// else {
// if ( chunk.length > 2 )
// return modify.insertWordIntoTopic(topic, '!'+groupid, 2);
// else if ( chunk.length == 2 )
// return modify.insertWordIntoTopic(topic, '!'+clientid, 2);
// else return "";
// }
// }
// else return "";
case '@private' : case '@private' :
console.log(modify.insertWordIntoTopic(topic, '!'+clientid, 1)); //console.log(modify.insertWordIntoTopic(topic, '!'+clientid, 1));
return modify.insertWordIntoTopic(topic, '!'+clientid, 1); return modify.insertWordIntoTopic(topic, '!'+clientid, 1);
} }
} }
......
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