UNPKG

sensecap

Version:

## Install ``` npm install sensecap --save ```

94 lines (90 loc) 2.8 kB
var assert = require('assert'); var GroupNetModule = require('../module/GroupNetModule'); var GroupModel = require('../model/GroupModel'); var GroupResult = require('../result/GroupResult'); function GroupManager(baseRequest) { this.groupNetModule = new GroupNetModule(baseRequest); } GroupManager.prototype = { /** * 创建分组 */ createGroup: function (groupName, callback) { var that = this; this.groupNetModule.createGroup(groupName, function (error, body) { var groupModel = null; if (!error) { var data = body.data; groupModel = new GroupModel(that, data.group_name, data.group_uuid); } if (callback) { callback(error, groupModel); } }) }, /** * 获取分组 */ getGroupList: function (groupUUIDs, callback) { var that = this; if ((typeof groupUUIDs === 'function') && !callback) { callback = groupUUIDs groupUUIDs = null } // groupUUIDs没设置则返回所有 this.groupNetModule.listGroups(groupUUIDs, function (error, body) { var groupList = []; if (!error) { var data = body.data; if (data && data.length > 0) { for (var i = 0; i < data.length; i++) { var item = data[i]; var groupModel = new GroupModel(that, item.group_name, item.group_uuid); groupList.push(groupModel); } } } if (callback) { callback(error, groupList); } }) }, /** * 分组重命名 */ renameGroup: function (groupName, groupUUID, callback) { this.groupNetModule.updateGroup(groupUUID, groupName, function (error, body) { if (callback) { callback(error); } }) }, /** * 删除分组 */ deleteGroup: function (groupUUIDs, callback) { assert(groupUUIDs, 'groupUUIDs is required'); this.groupNetModule.deleteGroup(groupUUIDs, function (error, body) { if (callback) { callback(error, body); } }) }, /** * 获取分组 */ batchQueryGroupByUUID: function (groupUUIDs) { assert(groupUUIDs, 'groupUUIDs is required'); var groupResult = new GroupResult(this); groupResult.setGroupUUIDs(groupUUIDs); return groupResult; }, /** * 获取全部分组 */ queryAllGroups: function () { var groupResult = new GroupResult(this); return groupResult; }, }; module.exports = GroupManager;