const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
class LaunchchannelService extends ServiceBase {
  constructor() {
    super("common", ServiceBase.getDaoName(LaunchchannelService));
  }

  /**
   * 根据company_id 和 code 去重
   * @param pobj
   * @returns {Promise<{msg: string, data: *, bizmsg: string, status: number}|{msg: *, data: *, status: *}>}
   */
  async createChannel(pobj){
    if(!pobj.company_id){
      return system.getResult(null,'company_id can not be empty');
    }
    if(!pobj.name){
      return system.getResult(null,'name can not be empty');
    }
    if(!pobj.code){
      return system.getResult(null,'code can not be empty');
    }
    let whereParams = {
      code:pobj.code,
      company_id:pobj.company_id
    }
    let searchResult = await this.findOne(whereParams,[]);
    if(searchResult){
      return null;
    }
    let channelData = {
      name:pobj.name,
      code:pobj.code,
      user_id:pobj.userid,
      user_name:pobj.username,
      company_id:pobj.company_id
    }
    let result= await this.create(channelData);
    return result;
  }

}
module.exports = LaunchchannelService;