const system = require("../../../system");
const Dao = require("../../dao.base");
class SaasorderbusinessmenDao extends Dao {
  constructor() {
    super(Dao.getModelName(SaasorderbusinessmenDao));
  }

  async mapByCreditCodes(params) {
    let creditCodes = params.creditCodes;
    let attrs = params.attrs || "*";
    let result = {};
    if (!creditCodes || creditCodes.length == 0) {
      return result;
    }
    let sql = [];
    sql.push("SELECT");
    sql.push(attrs);
    sql.push("FROM");
    sql.push(this.model.tableName);
    sql.push("WHERE credit_code IN (:creditCodes)");
    if (params.saas_merchant_id) {
      sql.push("AND merchant_id = :saas_merchant_id");
    }
    if (params.merchant_id) {
      sql.push("AND merchant_id = :merchant_id");
    }
    let list = await this.customQuery(sql.join(" "), params) || [];
    if (list.length == 0) {
      return result;
    }
    for (var item of list) {
      result[item.credit_code] = item;
    }
    return result;
  }

}
module.exports = SaasorderbusinessmenDao;