var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings=require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
class DataauthCtl extends CtlBase{
   constructor(){
     super("auth",CtlBase.getServiceName(DataauthCtl));
   }
   async saveauth(qobj,querybij,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(","),
            app_id:req.appid,
      });
      return system.getResult(u);
  }
  async fetchInitAuth(qobj,querybij,req){
    var uid=qobj.uid;
    var refmodel=qobj.modelname;
    var authtmp=await this.service.findOne({user_id:uid,modelname:refmodel,app_id:req.appid});
    if(authtmp){
      var auths= authtmp.auths;
      var arys=auths.split(",");
      return system.getResult(arys);
    }else{
      return system.getResultSuccess([]);
    }
  }
}
module.exports=DataauthCtl;
