const {
    Telegraf
} = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN)
const {
    UserModel,
    BusinessModel
} = global.config

module.exports = async (ctx) => {
    let data = ctx.update.callback_query.data;
    let user = await UserModel.findByPk(ctx.from.id)
    if (user.business.id == 0) return await ctx.reply(`Вы не состоите в организации.`)
    let business = await BusinessModel.findOne({
        where: {
        owner: user.business.id
      }
    })
    user.business = {
        id: 0,
        checks: 0,
        percent: 0
    }
    business.users = business.users.filter(value => value != ctx.from.id);
    business.save()
    user.save()
    return await bot.telegram.sendMessage(ctx.from.id, `🏭 Вы покинули ${business.name}`)
}