var system=require("../../system")
var settings=require("../../../config/settings");
const CtlBase = require("../ctl.base");
class DataauthCtl extends CtlBase{
   constructor(){
     super(CtlBase.getServiceName(DataauthCtl));
   }
   async saveauth(querybij,qobj,req){
      var arys=qobj.arys;
      var uid=qobj.uid;
      var refmodel=qobj.modelname;
      var u=await this.service.saveauth({
            user_id:uid,
            modelname:refmodel,
            auths:arys.join(","),
            company_id:req.companyid,
      });
      return system.getResult2(u,null);
  }
  async fetchInitAuth(querybij,qobj,req){
    var uid=qobj.uid;
    var refmodel=qobj.modelname;
    var authtmp=await this.service.findOne({user_id:uid,modelname:refmodel});
    if(authtmp){
      var auths= authtmp.auths;
      var arys=auths.split(",");
      return system.getResult2(arys,null);
    }else{
      return system.getResult2([],null);
    }
  }
}
module.exports=DataauthCtl;
