diff --git a/apps/bot/src/api.ts b/apps/bot/src/api.ts deleted file mode 100644 index ed4ade7..0000000 --- a/apps/bot/src/api.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as api from '@repo/graphql/api'; - -export async function getCustomer(telegramId: number) { - const response = await api.getCustomer({ telegramId }); - const customer = response?.data?.customers?.at(0); - - return customer; -} diff --git a/apps/bot/src/index.ts b/apps/bot/src/index.ts index 1033000..5101972 100644 --- a/apps/bot/src/index.ts +++ b/apps/bot/src/index.ts @@ -1,9 +1,8 @@ /* 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 { createOrUpdateClient, createOrUpdateUser } from '@repo/graphql/api'; +import { createOrUpdateClient, createOrUpdateUser, getCustomer } from '@repo/graphql/api'; import { Enum_Customer_Role } from '@repo/graphql/types'; import { Telegraf } from 'telegraf'; import { message } from 'telegraf/filters'; @@ -11,7 +10,7 @@ import { message } from 'telegraf/filters'; const bot = new Telegraf(environment.BOT_TOKEN); bot.start(async (context) => { - const customer = await getCustomer(context.from.id); + const customer = await getCustomer({ telegramId: context.from.id }); if (customer) { return context.reply( @@ -28,7 +27,7 @@ bot.start(async (context) => { }); bot.command('addcontact', async (context) => { - const customer = await getCustomer(context.from.id); + const customer = await getCustomer({ telegramId: context.from.id }); if (!customer) { return context.reply( @@ -41,7 +40,7 @@ bot.command('addcontact', async (context) => { }); bot.on(message('contact'), async (context) => { - const customer = await getCustomer(context.from.id); + const customer = await getCustomer({ telegramId: context.from.id }); const isRegistration = !customer; const { contact } = context.message; diff --git a/packages/graphql/api/customer.ts b/packages/graphql/api/customer.ts index c0fcce6..e2eb985 100644 --- a/packages/graphql/api/customer.ts +++ b/packages/graphql/api/customer.ts @@ -61,10 +61,14 @@ export async function createOrUpdateClient(variables: GQL.CreateClientMutationVa export async function getCustomer(variables: GQL.GetCustomerQueryVariables) { const { query } = await getClientWithToken(); - return query({ + const response = await query({ query: GQL.GetCustomerDocument, variables, }); + + const customer = response?.data?.customers?.at(0); + + return customer; } export async function updateCustomerProfile(variables: GQL.UpdateCustomerProfileMutationVariables) {