const system = require("../../system");
const ServiceBase = require("../sve.base");
class UserbpocompanyService extends ServiceBase {
  constructor() {
    super(ServiceBase.getDaoName(UserbpocompanyService));
  }

  async save(userId, names) {
    await this.delByUserId(userId);
    if (!names || names.length == 0) {
      return;
    }

    var companys = [];
    for (var n of names) {
      companys.push({
        user_id: userId,
        companyName: n
      });
    }
    await this.dao.model.bulkCreate(companys);
    return 1
  }

  async delByUserId(userId) {
    var sql = "DELETE FROM `p_user_bpocompany` WHERE user_id = " + userId;
    return await this.dao.customExecAddOrPutSql(sql);
  }

  async byUserId(userId) {
    return await this.dao.model.findAll({
      where: {
        user_id: userId
      }
    });
  }
}
module.exports = UserbpocompanyService;