apps/bot: команда /becomemaster
This commit is contained in:
parent
c18e2b75a3
commit
87d327fe9f
@ -1,9 +1,14 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
/* eslint-disable consistent-return */
|
||||
import { env as environment } from './config/env';
|
||||
import { commandsList, KEYBOARD_REMOVE, KEYBOARD_SHARE_PHONE } from './message';
|
||||
import { commandsList, KEYBOARD_REMOVE, KEYBOARD_SHARE_PHONE, MESSAGE_NOT_MASTER } from './message';
|
||||
import { normalizePhoneNumber } from './utils/phone';
|
||||
import { createOrUpdateUser, getCustomer, updateCustomerMaster } from '@repo/graphql/api';
|
||||
import {
|
||||
createOrUpdateUser,
|
||||
getCustomer,
|
||||
updateCustomerMaster,
|
||||
updateCustomerProfile,
|
||||
} from '@repo/graphql/api';
|
||||
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||
import { Telegraf } from 'telegraf';
|
||||
import { message } from 'telegraf/filters';
|
||||
@ -37,9 +42,36 @@ bot.command('addcontact', async (context) => {
|
||||
);
|
||||
}
|
||||
|
||||
if (customer.role !== Enum_Customer_Role.Master) {
|
||||
return context.reply(MESSAGE_NOT_MASTER);
|
||||
}
|
||||
|
||||
return context.reply('Отправьте контакт клиента, которого вы хотите добавить');
|
||||
});
|
||||
|
||||
bot.command('becomemaster', async (context) => {
|
||||
const customer = await getCustomer({ telegramId: context.from.id });
|
||||
|
||||
if (!customer) {
|
||||
return context.reply('Сначала поделитесь своим номером телефона.', KEYBOARD_SHARE_PHONE);
|
||||
}
|
||||
|
||||
if (customer.role === Enum_Customer_Role.Master) {
|
||||
return context.reply('Вы уже являетесь мастером.');
|
||||
}
|
||||
|
||||
const response = await updateCustomerProfile({
|
||||
data: { role: Enum_Customer_Role.Master },
|
||||
documentId: customer.documentId,
|
||||
}).catch((error) => {
|
||||
context.reply('Произошла ошибка.\n' + error);
|
||||
});
|
||||
|
||||
if (response) {
|
||||
return context.reply('Вы стали мастером');
|
||||
}
|
||||
});
|
||||
|
||||
bot.on(message('contact'), async (context) => {
|
||||
const customer = await getCustomer({ telegramId: context.from.id });
|
||||
const isRegistration = !customer;
|
||||
@ -66,9 +98,7 @@ bot.on(message('contact'), async (context) => {
|
||||
}
|
||||
} else {
|
||||
if (customer.role !== Enum_Customer_Role.Master) {
|
||||
return context.reply(
|
||||
'Только мастер может добавлять контакты. \nСтать мастером можно на странице профиля в приложении.',
|
||||
);
|
||||
return context.reply(MESSAGE_NOT_MASTER);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@ -24,3 +24,6 @@ export const KEYBOARD_REMOVE = {
|
||||
remove_keyboard: true,
|
||||
} as ReplyKeyboardRemove,
|
||||
};
|
||||
|
||||
export const MESSAGE_NOT_MASTER =
|
||||
'Только мастер может добавлять контакты. \nСтать мастером можно на странице профиля в приложении или при помощи команды /becomemaster';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user