var Service = require('Service');
var utils = require('utils');
var Dep = require('../../dao/dep');
var util = require('util');

/**
 * 获得部门列表
 */
var GetListAll = function() { 
  Service.call(this);
  this.connectDb = false;
};

util.inherits(GetListAll, Service);

module.exports = GetListAll;

/**
 * 处理服务请求
 * @param  {Object} req 服务请求对象
 * @param  {Object} res 服务响应对象
 */
GetListAll.prototype.process =  function(req, res) {
  var self = this;
  req.session.cache.getList('dep', {fields: "id,name,parent_id"}, function(err, deps){
  	if(err) {
  		self.onLogicError(1, err.message, req, res);
  		return;
  	}
    res.deps = deps;
  	/*res.deps = { fields: ["id", "name", "parent_id"], data: [] };
    for(var i=0;i<deps.length;i++) {
      let dep = deps[i];
      res.deps.data.push([dep.id, dep.name, dep.parent_id]);
    }*/
  	self.end(res);
  });
};