CampFirePlay/commands/organization/inviteAction.js
Degradin baa0b5f3a9 global refactoring
Все переведено в модули
2023-10-08 23:43:12 +03:00

34 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const sequelize = require('/workspace/degradin/Dev/Telegram/CampFire Play/db');
const { Op } = require('sequelize');
const {
UserModel,
BusinessModel
} = require('/workspace/degradin/Dev/Telegram/CampFire Play/config')
module.exports = async (ctx) => {
let data = ctx.update.callback_query.data;
data = JSON.parse(data)
let user = await UserModel.findByPk(ctx.update.callback_query.from.id)
if (data.type == 'business_invite_accept') {
if(user.business.id == 0){
let business = await BusinessModel.findOne({
where: {
owner: data.invitor
}
})
user.business = {
id: data.invitor,
checks: 0,
percent: 10
}
business.users = sequelize.fn('array_append', sequelize.col('users'), ctx.update.callback_query.from.id);
business.save()
user.save()
await ctx.telegram.answerCbQuery(ctx.callbackQuery.id, `✔️ Приглашение принято.`, {show_alert: true})
}
await ctx.telegram.answerCbQuery(ctx.callbackQuery.id, ` Вы уже в организации.`, {show_alert: true})
}
if (data.type == 'business_invite_refuse'){
await ctx.telegram.answerCbQuery(ctx.callbackQuery.id, `❌ Приглашение отклонено.`, {show_alert: true})
}
}