From b1321e751d653819445039cdd81d19e35d9a0471 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 10 Jan 2025 18:40:58 +0300 Subject: [PATCH] apps/bot: check role 'master' before add contact --- apps/bot/src/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/bot/src/index.ts b/apps/bot/src/index.ts index e8a2458..e1d2032 100644 --- a/apps/bot/src/index.ts +++ b/apps/bot/src/index.ts @@ -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) {