apps/bot: remove api.ts -> move getCustomer to packages/graphql/api

This commit is contained in:
vchikalkin 2025-01-12 12:40:17 +03:00
parent f1e12a48aa
commit cd027f29e6
3 changed files with 9 additions and 14 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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) {