
const { empty } = require("../Helpers/Common");
const sequelize = require("../config/dbconnection");
const Sequelize = require('sequelize')
const partnerGroup = sequelize.define('partner_group', {
    id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true },
    partner_id: { type: Sequelize.INTEGER, allowNull: false },
    group_id: { type: Sequelize.INTEGER, allowNull: false },
    added_by: { type: Sequelize.INTEGER, allowNull: false },
   
    timestamp: { type: Sequelize.INTEGER, allowNull: true, defaultValue: null },
    status: { type: Sequelize.INTEGER, allowNull: true, defaultValue: 1 },
    
},{timestamps: false})
const getAllGroups=async()=>{
    try {
        let result = await sequelize.query(`
        select g.* from groups as g where g.status = 1 order by g.id desc`)
        if(!empty(result)){
            if (result[0].length > 0) {
                data = result[0];
              }
              return data;
        }else{
            return false
        }
    } catch (error) {
        console.log(error)
    }
}
const addPartnerGroup = async (data) => {
    try {
      let results = await partnerGroup.create(data)
      if (results) {
        return results;
      }
      else {
        return false;
      }
    } catch (error) {
      console.log(error, 'error in adding partner group')
    }
  }
  

module.exports={
    getAllGroups,addPartnerGroup
}