const system=require("../../../system");
const Dao=require("../../dao.base");
class RoleDao extends Dao{
  constructor(){
    super(Dao.getModelName(RoleDao));
  }
  async findOne(paramappid,t){
    var app=  await this.model.findOne({where:{appid:paramappid}},{transaction:t});
    return app;
  }
  extraWhere(obj,w,qc,linkAttrs){
    // if(obj.codepath && obj.codepath!=""){
    //  //  if(obj.codepath.indexOf("userarch")>0){//说明是应用管理员的查询
    //  //    console.log(obj);
    //  //     w["app_id"]=obj.appid;
    //  //  }
    // }
    w["app_id"]=obj.appid;
    w["company_id"]=obj.tocompanyid;
    return w;
 }
  extraModelFilter(){
    return {"key":"include","value":[{model:this.db.models.app,}]};
  }
  async preUpdate(u){
    return u;
  }
  async update(obj){
    var obj2=await this.preUpdate(obj);
    await this.model.update(obj2,{where:{id:obj2.id}});
    var role=await this.model.findOne({where:{id:obj2.id}});
    return role;
  }
  async preCreate(u){
    return u;
  }
  async create(u,t){
      var self=this;
      var u2= await this.preCreate(u);
      if(t){
         var role= await this.model.create(u2,{transaction: t});
         return role;
      }else{
        var role= await this.model.create(u2);
        return role;
      }
  }
}
module.exports=RoleDao;
