apps/bot: check role 'master' before add contact

This commit is contained in:
vchikalkin 2025-01-10 18:40:58 +03:00
parent d723758704
commit b1321e751d

View File

@ -1,8 +1,10 @@
/* eslint-disable canonical/id-match */
/* eslint-disable consistent-return */
import { getCustomer } from './api';
import { env as environment } from './config/env';
import { commandsList, KEYBOARD_REMOVE, KEYBOARD_SHARE_PHONE } from './message';
import { createClient, createCustomer } from '@repo/graphql/api';
import { Enum_Customer_Role } from '@repo/graphql/types';
import { Telegraf } from 'telegraf';
import { message } from 'telegraf/filters';
@ -49,7 +51,7 @@ bot.on(message('contact'), async (context) => {
phone: context.message.contact.phone_number,
telegramId: context.from.id,
}).catch((error) => {
context.reply('Произошла ошибка, попробуйте позже.' + error);
context.reply('Произошла ошибка.\n' + error);
});
if (response) {
@ -60,12 +62,18 @@ bot.on(message('contact'), async (context) => {
);
}
} else {
if (customer.role !== Enum_Customer_Role.Master) {
return context.reply(
'Только мастер может добавлять контакты. \nСтать мастером можно на странице профиля в приложении.',
);
}
const { contact } = context.message;
const name = (contact.first_name || '') + ' ' + (contact.last_name || '').trim();
const phone = contact.phone_number;
const response = await createClient({ name, phone }).catch((error) => {
context.reply('Произошла ошибка, попробуйте позже.\n' + error);
context.reply('Произошла ошибка.\n' + error);
});
if (response) {