ApiGroupController.prototype.getGroupUserRelated = function(ref_profile_owner, callback) { var Group = require('app/models/group'); var groupFind = Group.find(); var aryMember = new Array(); aryMember.push(new Object(ref_profile_owner)); groupFind.select('_id'); groupFind.where('ref_profile_member').in(aryMember); groupFind.exec(function(err, aryGroup) { var groupFind = Group.find(); groupFind.select('_id'); groupFind.and([{'ref_profile_owner': ref_profile_owner}]); groupFind.exec(function(err, aryGroupOwner) { var aryContact = aryGroup.concat(aryGroupOwner); var aryIds = []; for (var i in aryContact) { aryIds.push(aryContact[i]._id.toString()); } aryIds = aryIds.filter(function(item, pos) { return aryIds.indexOf(item) == pos; }); callback(aryIds); }); }); };
groupFind.exec(function(err, aryGroup) { var groupFind = Group.find(); groupFind.select('_id'); groupFind.and([{'ref_profile_owner': ref_profile_owner}]); groupFind.exec(function(err, aryGroupOwner) { var aryContact = aryGroup.concat(aryGroupOwner); var aryIds = []; for (var i in aryContact) { aryIds.push(aryContact[i]._id.toString()); } aryIds = aryIds.filter(function(item, pos) { return aryIds.indexOf(item) == pos; }); callback(aryIds); }); });