From fc94f373e9b82476359f1e4e0199cf4ce73e12ec Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 16 May 2025 12:55:50 +0300 Subject: [PATCH] refactor customer api --- apps/web/actions/api/customers.ts | 50 +++++++ apps/web/actions/api/lib/service.ts | 22 +++ apps/web/actions/contacts.ts | 26 ---- apps/web/actions/orders.ts | 14 +- apps/web/actions/profile.ts | 37 ----- apps/web/actions/services.ts | 8 +- apps/web/actions/session.ts | 12 ++ apps/web/actions/slots.ts | 13 +- apps/web/components/auth/update-profile.tsx | 10 +- .../web/components/contacts/contacts-list.tsx | 2 +- .../orders/components/contacts-grid/index.tsx | 4 +- apps/web/components/profile/data-card.tsx | 16 +- apps/web/components/profile/links-card.tsx | 4 +- apps/web/components/profile/person-card.tsx | 4 +- apps/web/hooks/{ => api}/contacts/index.ts | 0 apps/web/hooks/api/contacts/query.ts | 25 ++++ .../contacts/use-customer-contacts.ts | 20 +-- apps/web/hooks/api/customers.ts | 24 +++ apps/web/hooks/contacts/query.ts | 8 - apps/web/hooks/profile/index.ts | 23 --- apps/web/stores/order/hooks.tsx | 16 +- packages/graphql/api/base.ts | 15 ++ packages/graphql/api/customer.ts | 108 -------------- packages/graphql/api/customers.ts | 140 ++++++++++++++++++ packages/graphql/api/index.ts | 4 +- packages/graphql/eslint.config.js | 2 +- packages/graphql/operations/customer.graphql | 2 +- packages/graphql/package.json | 8 +- .../graphql/types/operations.generated.ts | 6 +- packages/typescript-config/base.json | 4 +- pnpm-lock.yaml | 3 + 31 files changed, 361 insertions(+), 269 deletions(-) create mode 100644 apps/web/actions/api/customers.ts create mode 100644 apps/web/actions/api/lib/service.ts delete mode 100644 apps/web/actions/contacts.ts delete mode 100644 apps/web/actions/profile.ts create mode 100644 apps/web/actions/session.ts rename apps/web/hooks/{ => api}/contacts/index.ts (100%) create mode 100644 apps/web/hooks/api/contacts/query.ts rename apps/web/hooks/{ => api}/contacts/use-customer-contacts.ts (62%) create mode 100644 apps/web/hooks/api/customers.ts delete mode 100644 apps/web/hooks/contacts/query.ts delete mode 100644 apps/web/hooks/profile/index.ts create mode 100644 packages/graphql/api/base.ts delete mode 100644 packages/graphql/api/customer.ts create mode 100644 packages/graphql/api/customers.ts diff --git a/apps/web/actions/api/customers.ts b/apps/web/actions/api/customers.ts new file mode 100644 index 0000000..85e3a1c --- /dev/null +++ b/apps/web/actions/api/customers.ts @@ -0,0 +1,50 @@ +'use server'; + +import { useService } from './lib/service'; +import { CustomersService } from '@repo/graphql/api/customers'; + +const getService = useService(CustomersService); + +export async function createOrUpdateCustomer( + ...variables: Parameters +) { + const service = await getService(); + + return service.createOrUpdateCustomer(...variables); +} + +export async function getCustomer(...variables: Parameters) { + const service = await getService(); + + return service.getCustomer(...variables); +} + +export async function getCustomerClients( + ...variables: Parameters +) { + const service = await getService(); + + return service.getCustomerClients(...variables); +} + +export async function getCustomerMasters( + ...variables: Parameters +) { + const service = await getService(); + + return service.getCustomerMasters(...variables); +} + +export async function updateCustomer(...variables: Parameters) { + const service = await getService(); + + return service.updateCustomer(...variables); +} + +export async function updateCustomerMaster( + ...variables: Parameters +) { + const service = await getService(); + + return service.updateCustomerMaster(...variables); +} diff --git a/apps/web/actions/api/lib/service.ts b/apps/web/actions/api/lib/service.ts new file mode 100644 index 0000000..9f99685 --- /dev/null +++ b/apps/web/actions/api/lib/service.ts @@ -0,0 +1,22 @@ +/* eslint-disable canonical/id-match */ +import { authOptions } from '@/config/auth'; +import { type BaseService } from '@repo/graphql/api/base'; +import { getServerSession } from 'next-auth'; + +export async function _temporaryGetCustomer() { + const session = await getServerSession(authOptions); + if (!session?.user?.telegramId) throw new Error('Unauthorized'); + + return { telegramId: session.user.telegramId }; +} + +export function useService(service: T) { + return async function () { + const session = await getServerSession(authOptions); + if (!session?.user?.telegramId) throw new Error('Unauthorized'); + + const customer = { telegramId: session.user.telegramId }; + + return new service(customer) as InstanceType; + }; +} diff --git a/apps/web/actions/contacts.ts b/apps/web/actions/contacts.ts deleted file mode 100644 index 3b1bcf4..0000000 --- a/apps/web/actions/contacts.ts +++ /dev/null @@ -1,26 +0,0 @@ -'use server'; -import { authOptions } from '@/config/auth'; -import { getCustomerClients, getCustomerMasters } from '@repo/graphql/api'; -import { getServerSession } from 'next-auth/next'; - -export async function getClients() { - const session = await getServerSession(authOptions); - if (!session) throw new Error('Missing session'); - - const { user } = session; - - const response = await getCustomerClients({ telegramId: user?.telegramId }); - - return response.data?.customers?.at(0); -} - -export async function getMasters() { - const session = await getServerSession(authOptions); - if (!session) throw new Error('Missing session'); - - const { user } = session; - - const response = await getCustomerMasters({ telegramId: user?.telegramId }); - - return response.data?.customers?.at(0); -} diff --git a/apps/web/actions/orders.ts b/apps/web/actions/orders.ts index 600ff09..70d0112 100644 --- a/apps/web/actions/orders.ts +++ b/apps/web/actions/orders.ts @@ -2,7 +2,8 @@ 'use server'; // eslint-disable-next-line sonarjs/no-internal-api-use import type * as ApolloTypes from '../../../packages/graphql/node_modules/@apollo/client/core'; -import { getProfile } from './profile'; +import { getCustomer, getCustomerMasters } from './api/customers'; +import { _temporaryGetCustomer } from './api/lib/service'; import { formatDate, formatTime, sumTime } from '@/utils/date'; import * as api from '@repo/graphql/api'; import { Enum_Customer_Role, Enum_Slot_State } from '@repo/graphql/types'; @@ -21,7 +22,12 @@ type OrderInput = { }; export async function createOrder(input: OrderInput) { - const customer = await getProfile(); + const variables = await _temporaryGetCustomer(); + const { customer } = await getCustomer(variables); + + if (!customer) { + throw new Error('Missing customer'); + } if (!input.slotId) { throw new Error('Missing slot'); @@ -40,9 +46,9 @@ export async function createOrder(input: OrderInput) { const masterId = data.slot?.master?.documentId; - const masters = await api.getCustomerMasters(customer); + const masters = await getCustomerMasters(customer); - if (!masters.data.customers.some((master) => master?.documentId === masterId)) { + if (!masters.customers.some((master) => master?.documentId === masterId)) { throw new Error('Invalid master'); } } diff --git a/apps/web/actions/profile.ts b/apps/web/actions/profile.ts deleted file mode 100644 index 021ec7a..0000000 --- a/apps/web/actions/profile.ts +++ /dev/null @@ -1,37 +0,0 @@ -'use server'; -import { authOptions } from '@/config/auth'; -import { getCustomer, updateCustomerProfile } from '@repo/graphql/api'; -import { type CustomerInput, type GetCustomerQueryVariables } from '@repo/graphql/types'; -import { getServerSession } from 'next-auth/next'; - -export async function getProfile(input?: GetCustomerQueryVariables) { - const session = await getServerSession(authOptions); - if (!session) throw new Error('Missing session'); - - const { user } = session; - const telegramId = input?.telegramId || user?.telegramId; - - const { data } = await getCustomer({ telegramId }); - const customer = data?.customers?.at(0); - - if (!customer) throw new Error('Customer not found'); - - return customer; -} - -export async function updateProfile(input: CustomerInput) { - const session = await getServerSession(authOptions); - if (!session) throw new Error('Missing session'); - - const { user } = session; - - const { data } = await getCustomer({ telegramId: user?.telegramId }); - const customer = data.customers.at(0); - - if (!customer) throw new Error('Customer not found'); - - await updateCustomerProfile({ - data: input, - documentId: customer?.documentId, - }); -} diff --git a/apps/web/actions/services.ts b/apps/web/actions/services.ts index fa19552..6cec874 100644 --- a/apps/web/actions/services.ts +++ b/apps/web/actions/services.ts @@ -1,5 +1,6 @@ 'use server'; -import { getProfile } from './profile'; +import { getCustomer } from './api/customers'; +import { _temporaryGetCustomer } from './api/lib/service'; import * as api from '@repo/graphql/api/service'; // eslint-disable-next-line sonarjs/no-internal-api-use import type * as ApolloTypes from '@repo/graphql/node_modules/@apollo/client/core'; @@ -9,9 +10,10 @@ import { type GetServicesQueryVariables } from '@repo/graphql/types'; type FixTypescriptCringe = ApolloTypes.FetchResult; export async function getServices(input?: GetServicesQueryVariables) { - const customer = await getProfile(); + const variables = await _temporaryGetCustomer(); + const { customer } = await getCustomer(variables); - const filters = input || { filters: { master: { documentId: { eq: customer.documentId } } } }; + const filters = input || { filters: { master: { documentId: { eq: customer?.documentId } } } }; return api.getServices(filters); } diff --git a/apps/web/actions/session.ts b/apps/web/actions/session.ts new file mode 100644 index 0000000..7ef1c33 --- /dev/null +++ b/apps/web/actions/session.ts @@ -0,0 +1,12 @@ +'use server'; +import { authOptions } from '@/config/auth'; +import { getServerSession } from 'next-auth/next'; + +export async function getSessionUser() { + const session = await getServerSession(authOptions); + const user = session?.user; + + if (!user?.telegramId) throw new Error('Missing session'); + + return user; +} diff --git a/apps/web/actions/slots.ts b/apps/web/actions/slots.ts index 19d7dff..ca5bae0 100644 --- a/apps/web/actions/slots.ts +++ b/apps/web/actions/slots.ts @@ -1,7 +1,8 @@ 'use server'; // eslint-disable-next-line sonarjs/no-internal-api-use import type * as ApolloTypes from '../../../packages/graphql/node_modules/@apollo/client/core'; -import { getProfile } from './profile'; +import { getCustomer } from './api/customers'; +import { _temporaryGetCustomer } from './api/lib/service'; import { formatDate, formatTime } from '@/utils/date'; import * as api from '@repo/graphql/api'; import type * as GQL from '@repo/graphql/types'; @@ -12,7 +13,8 @@ type AddSlotInput = Omit; type FixTypescriptCringe = ApolloTypes.FetchResult; export async function addSlot(input: AddSlotInput) { - const customer = await getProfile(); + const variables = await _temporaryGetCustomer(); + const { customer } = await getCustomer(variables); return api.createSlot({ ...input, @@ -24,13 +26,14 @@ export async function addSlot(input: AddSlotInput) { } export async function getSlots(input: GQL.GetSlotsQueryVariables) { - const customer = await getProfile(); + const variables = await _temporaryGetCustomer(); + const { customer } = await getCustomer(variables); return api.getSlots({ filters: { master: { documentId: { - eq: customer.documentId, + eq: customer?.documentId, }, }, ...input.filters, @@ -39,8 +42,6 @@ export async function getSlots(input: GQL.GetSlotsQueryVariables) { } export async function updateSlot(input: GQL.UpdateSlotMutationVariables) { - await getProfile(); - return api.updateSlot({ ...input, data: { diff --git a/apps/web/components/auth/update-profile.tsx b/apps/web/components/auth/update-profile.tsx index fae567e..2c110ca 100644 --- a/apps/web/components/auth/update-profile.tsx +++ b/apps/web/components/auth/update-profile.tsx @@ -1,18 +1,20 @@ 'use client'; -import { useProfileMutation } from '@/hooks/profile'; +import { useCustomerMutation } from '@/hooks/api/customers'; import { initData, useSignal } from '@telegram-apps/sdk-react'; import { useEffect, useState } from 'react'; export function UpdateProfile() { const initDataUser = useSignal(initData.user); - const { mutate: updateProfile } = useProfileMutation(); + const { mutate: updateProfile } = useCustomerMutation(); const [hasUpdated, setHasUpdated] = useState(false); useEffect(() => { if (!hasUpdated) { updateProfile({ - active: true, - photoUrl: initDataUser?.photoUrl || undefined, + data: { + active: true, + photoUrl: initDataUser?.photoUrl || undefined, + }, }); setHasUpdated(true); } diff --git a/apps/web/components/contacts/contacts-list.tsx b/apps/web/components/contacts/contacts-list.tsx index 3db173d..2bba376 100644 --- a/apps/web/components/contacts/contacts-list.tsx +++ b/apps/web/components/contacts/contacts-list.tsx @@ -1,6 +1,6 @@ 'use client'; import { LoadingSpinner } from '../common/spinner'; -import { useCustomerContacts } from '@/hooks/contacts'; +import { useCustomerContacts } from '@/hooks/api/contacts'; import * as GQL from '@repo/graphql/types'; import { Avatar, AvatarFallback, AvatarImage } from '@repo/ui/components/ui/avatar'; import Link from 'next/link'; diff --git a/apps/web/components/orders/components/contacts-grid/index.tsx b/apps/web/components/orders/components/contacts-grid/index.tsx index ec0612b..0b9eddc 100644 --- a/apps/web/components/orders/components/contacts-grid/index.tsx +++ b/apps/web/components/orders/components/contacts-grid/index.tsx @@ -2,13 +2,13 @@ import { ContactsGridBase } from './components'; import { LoadingSpinner } from '@/components/common/spinner'; import { ContactsFilterProvider } from '@/context/contacts-filter'; -import { useCustomerContacts } from '@/hooks/contacts'; +import { useCustomerContacts } from '@/hooks/api/contacts'; import { useOrderStore } from '@/stores/order'; import { withContext } from '@/utils/context'; import { useEffect } from 'react'; export const MastersGrid = withContext(ContactsFilterProvider)(function () { - const { contacts, isLoading, setFilter } = useCustomerContacts({ includeSelf: true }); + const { contacts, isLoading, setFilter } = useCustomerContacts(); const masterId = useOrderStore((store) => store.masterId); const setMasterId = useOrderStore((store) => store.setMasterId); diff --git a/apps/web/components/profile/data-card.tsx b/apps/web/components/profile/data-card.tsx index 739f36d..afa5e0d 100644 --- a/apps/web/components/profile/data-card.tsx +++ b/apps/web/components/profile/data-card.tsx @@ -2,14 +2,14 @@ import { CardSectionHeader } from '../ui'; import { CheckboxWithText, DataField } from './components'; import { type ProfileProps } from './types'; -import { useProfileMutation, useProfileQuery } from '@/hooks/profile'; +import { useCustomerMutation, useCustomerQuery } from '@/hooks/api/customers'; import { Enum_Customer_Role as Role } from '@repo/graphql/types'; import { Button } from '@repo/ui/components/ui/button'; import { Card } from '@repo/ui/components/ui/card'; import Link from 'next/link'; export function ContactDataCard({ telegramId }: Readonly) { - const { data: customer } = useProfileQuery({ telegramId }); + const { data: { customer } = {} } = useCustomerQuery({ telegramId }); if (!customer) return null; @@ -30,8 +30,8 @@ export function ContactDataCard({ telegramId }: Readonly) { } export function ProfileDataCard() { - const { data: customer } = useProfileQuery(); - const { mutate: updateProfile } = useProfileMutation(); + const { data: { customer } = {} } = useCustomerQuery(); + const { mutate: updateCustomer } = useCustomerMutation(); if (!customer) return null; @@ -43,14 +43,18 @@ export function ProfileDataCard() { fieldName="name" id="name" label="Имя" - onChange={updateProfile} + onChange={({ name }) => updateCustomer({ data: { name } })} value={customer?.name ?? ''} /> updateProfile({ role: checked ? Role.Master : Role.Client })} + onChange={(checked) => + updateCustomer({ + data: { role: checked ? Role.Master : Role.Client }, + }) + } text="Быть мастером" /> diff --git a/apps/web/components/profile/links-card.tsx b/apps/web/components/profile/links-card.tsx index 0a7aa63..56cda90 100644 --- a/apps/web/components/profile/links-card.tsx +++ b/apps/web/components/profile/links-card.tsx @@ -2,11 +2,11 @@ 'use client'; import { LinkButton } from './components'; import { type ProfileProps } from './types'; -import { useProfileQuery } from '@/hooks/profile'; +import { useCustomerQuery } from '@/hooks/api/customers'; import { Enum_Customer_Role } from '@repo/graphql/types'; export function LinksCard({ telegramId }: Readonly) { - const { data: customer } = useProfileQuery({ telegramId }); + const { data: { customer } = {} } = useCustomerQuery({ telegramId }); const isMaster = customer?.role === Enum_Customer_Role.Master; diff --git a/apps/web/components/profile/person-card.tsx b/apps/web/components/profile/person-card.tsx index 0d15d9e..29fb5fa 100644 --- a/apps/web/components/profile/person-card.tsx +++ b/apps/web/components/profile/person-card.tsx @@ -1,12 +1,12 @@ 'use client'; import { LoadingSpinner } from '../common/spinner'; import { type ProfileProps } from './types'; -import { useProfileQuery } from '@/hooks/profile'; +import { useCustomerQuery } from '@/hooks/api/customers'; import { Avatar, AvatarFallback, AvatarImage } from '@repo/ui/components/ui/avatar'; import { Card } from '@repo/ui/components/ui/card'; export function PersonCard({ telegramId }: Readonly) { - const { data: customer, isLoading } = useProfileQuery({ telegramId }); + const { data: { customer } = {}, isLoading } = useCustomerQuery({ telegramId }); if (isLoading || !customer) return ( diff --git a/apps/web/hooks/contacts/index.ts b/apps/web/hooks/api/contacts/index.ts similarity index 100% rename from apps/web/hooks/contacts/index.ts rename to apps/web/hooks/api/contacts/index.ts diff --git a/apps/web/hooks/api/contacts/query.ts b/apps/web/hooks/api/contacts/query.ts new file mode 100644 index 0000000..f28aa61 --- /dev/null +++ b/apps/web/hooks/api/contacts/query.ts @@ -0,0 +1,25 @@ +import { getCustomerClients, getCustomerMasters } from '@/actions/api/customers'; +import { useQuery } from '@tanstack/react-query'; +import { useSession } from 'next-auth/react'; + +export const useClientsQuery = (props?: Parameters[0]) => { + const { data: session } = useSession(); + const telegramId = props?.telegramId || session?.user?.telegramId; + + return useQuery({ + enabled: false, + queryFn: () => getCustomerClients({ telegramId }), + queryKey: ['customer', 'telegramId', telegramId, 'clients', 'get'], + }); +}; + +export const useMastersQuery = (props?: Parameters[0]) => { + const { data: session } = useSession(); + const telegramId = props?.telegramId || session?.user?.telegramId; + + return useQuery({ + enabled: false, + queryFn: () => getCustomerMasters({ telegramId }), + queryKey: ['customer', 'telegramId', telegramId, 'masters', 'get'], + }); +}; diff --git a/apps/web/hooks/contacts/use-customer-contacts.ts b/apps/web/hooks/api/contacts/use-customer-contacts.ts similarity index 62% rename from apps/web/hooks/contacts/use-customer-contacts.ts rename to apps/web/hooks/api/contacts/use-customer-contacts.ts index 92b300d..2945af4 100644 --- a/apps/web/hooks/contacts/use-customer-contacts.ts +++ b/apps/web/hooks/api/contacts/use-customer-contacts.ts @@ -1,19 +1,11 @@ -/* eslint-disable canonical/id-match */ 'use client'; -import { useProfileQuery } from '../profile'; import { useClientsQuery, useMastersQuery } from './query'; import { ContactsFilterContext } from '@/context/contacts-filter'; -import { Enum_Customer_Role } from '@repo/graphql/types'; import { sift } from 'radash'; import { use, useEffect, useMemo } from 'react'; -type Parameters_ = { - includeSelf: boolean; -}; - -export function useCustomerContacts(parameters?: Parameters_) { +export function useCustomerContacts() { const { filter, setFilter } = use(ContactsFilterContext); - const { data: customer, isLoading: isLoadingProfile } = useProfileQuery(); const { data: clientsData, @@ -27,14 +19,10 @@ export function useCustomerContacts(parameters?: Parameters_) { refetch: refetchMasters, } = useMastersQuery(); - const clients = clientsData?.clients || []; - let masters = mastersData?.masters || []; + const clients = clientsData?.customers?.at(0)?.clients || []; + const masters = mastersData?.customers?.at(0)?.masters || []; - if (parameters?.includeSelf && customer?.role === Enum_Customer_Role.Master) { - masters = [{ ...customer, name: 'Я' }, ...masters]; - } - - const isLoading = isLoadingClients || isLoadingMasters || isLoadingProfile; + const isLoading = isLoadingClients || isLoadingMasters; useEffect(() => { if (filter === 'clients') { diff --git a/apps/web/hooks/api/customers.ts b/apps/web/hooks/api/customers.ts new file mode 100644 index 0000000..eac4886 --- /dev/null +++ b/apps/web/hooks/api/customers.ts @@ -0,0 +1,24 @@ +'use client'; +import { getCustomer, updateCustomer } from '@/actions/api/customers'; +import { useMutation, useQuery } from '@tanstack/react-query'; +import { useSession } from 'next-auth/react'; + +export const useCustomerQuery = (props?: Parameters[0]) => { + const { data: session } = useSession(); + const telegramId = props?.telegramId || session?.user?.telegramId; + + return useQuery({ + queryFn: () => getCustomer({ telegramId }), + queryKey: ['customer', 'telegramId', telegramId, 'get'], + }); +}; + +export const useCustomerMutation = () => { + const { refetch } = useCustomerQuery(); + + return useMutation({ + mutationFn: updateCustomer, + mutationKey: ['customer', 'update'], + onSuccess: () => refetch(), + }); +}; diff --git a/apps/web/hooks/contacts/query.ts b/apps/web/hooks/contacts/query.ts deleted file mode 100644 index 7c4c397..0000000 --- a/apps/web/hooks/contacts/query.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { getClients, getMasters } from '@/actions/contacts'; -import { useQuery } from '@tanstack/react-query'; - -export const useClientsQuery = () => - useQuery({ enabled: false, queryFn: getClients, queryKey: ['contacts', 'clients', 'get'] }); - -export const useMastersQuery = () => - useQuery({ enabled: false, queryFn: getMasters, queryKey: ['contacts', 'masters', 'get'] }); diff --git a/apps/web/hooks/profile/index.ts b/apps/web/hooks/profile/index.ts deleted file mode 100644 index 45bc79b..0000000 --- a/apps/web/hooks/profile/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -'use client'; -import { getProfile, updateProfile } from '@/actions/profile'; -import { type ProfileProps } from '@/components/profile/types'; -import { useMutation, useQuery } from '@tanstack/react-query'; - -export const useProfileQuery = (props?: ProfileProps) => { - const telegramId = props?.telegramId; - - return useQuery({ - queryFn: () => getProfile({ telegramId }), - queryKey: telegramId ? ['profile', 'telegramId', telegramId, 'get'] : ['profile', 'get'], - }); -}; - -export const useProfileMutation = () => { - const { refetch } = useProfileQuery(); - - return useMutation({ - mutationFn: updateProfile, - mutationKey: ['profile', 'update'], - onSuccess: () => refetch(), - }); -}; diff --git a/apps/web/stores/order/hooks.tsx b/apps/web/stores/order/hooks.tsx index b6091f3..2bfb40f 100644 --- a/apps/web/stores/order/hooks.tsx +++ b/apps/web/stores/order/hooks.tsx @@ -2,7 +2,7 @@ 'use client'; import { OrderStoreContext } from './context'; import { type OrderStore, type Steps } from './types'; -import { useProfileQuery } from '@/hooks/profile'; +import { useCustomerQuery } from '@/hooks/api/customers'; import { Enum_Customer_Role } from '@repo/graphql/types'; import { useContext, useEffect } from 'react'; import { useStore } from 'zustand'; @@ -28,7 +28,7 @@ export const MASTER_STEPS: Steps[] = STEPS.filter((step) => step !== 'master-sel export const CLIENT_STEPS: Steps[] = STEPS.filter((step) => step !== 'client-select'); export function useInitOrderStore() { - const { data } = useProfileQuery(); + const { data: { customer } = {} } = useCustomerQuery(); const setMasterId = useOrderStore((store) => store.setMasterId); const setClientId = useOrderStore((store) => store.setClientId); @@ -36,14 +36,14 @@ export function useInitOrderStore() { const setStepsSequence = useOrderStore((store) => store._setStepSequence); useEffect(() => { - const role = data?.role; + const role = customer?.role; - if (role === Enum_Customer_Role.Master && data) { - setMasterId(data?.documentId); + if (role === Enum_Customer_Role.Master && customer) { + setMasterId(customer?.documentId); } - if (role === Enum_Customer_Role.Client && data) { - setClientId(data?.documentId); + if (role === Enum_Customer_Role.Client && customer) { + setClientId(customer?.documentId); } const steps = role === Enum_Customer_Role.Master ? MASTER_STEPS : CLIENT_STEPS; @@ -51,5 +51,5 @@ export function useInitOrderStore() { setStepsSequence(steps); setStep(initialStep); - }, [data, setClientId, setMasterId, setStep, setStepsSequence]); + }, [customer, setClientId, setMasterId, setStep, setStepsSequence]); } diff --git a/packages/graphql/api/base.ts b/packages/graphql/api/base.ts new file mode 100644 index 0000000..c76043a --- /dev/null +++ b/packages/graphql/api/base.ts @@ -0,0 +1,15 @@ +type CustomerProfile = { + telegramId: string; +}; + +export class BaseService { + protected customer: CustomerProfile; + + constructor(customer: CustomerProfile) { + if (!customer?.telegramId) { + throw new Error('Invalid customer profile: telegramId required'); + } + + this.customer = customer; + } +} diff --git a/packages/graphql/api/customer.ts b/packages/graphql/api/customer.ts deleted file mode 100644 index 024a0de..0000000 --- a/packages/graphql/api/customer.ts +++ /dev/null @@ -1,108 +0,0 @@ -'use server'; -import { getClientWithToken } from '../apollo/client'; -import * as GQL from '../types'; - -export async function createOrUpdateUser(input: GQL.CreateCustomerMutationVariables) { - if (!input.phone && !input.telegramId) throw new Error('Missing phone and telegramId'); - - const { query, mutate } = await getClientWithToken(); - - const response = await query({ - query: GQL.GetCustomerDocument, - variables: input, - }); - - const customer = response?.data?.customers?.at(0); - - if (customer && customer.phone === input.phone) { - return mutate({ - mutation: GQL.UpdateCustomerProfileDocument, - variables: { - documentId: customer.documentId, - data: { ...input }, - }, - }); - } - - return mutate({ - mutation: GQL.CreateCustomerDocument, - variables: input, - }); -} - -export async function getCustomer(input: GQL.GetCustomerQueryVariables) { - const { query } = await getClientWithToken(); - - return query({ - query: GQL.GetCustomerDocument, - variables: input, - }); -} - -export async function getCustomerMasters(input: GQL.GetCustomerMastersQueryVariables) { - const { query } = await getClientWithToken(); - - return query({ - query: GQL.GetCustomerMastersDocument, - variables: input, - }); -} - -export async function getCustomerClients(input: GQL.GetCustomerClientsQueryVariables) { - const { query } = await getClientWithToken(); - - return query({ - query: GQL.GetCustomerClientsDocument, - variables: input, - }); -} - -type AddCustomerMasterInput = Pick & { - masterId: GQL.Scalars['ID']['input']; - operation: 'add' | 'remove'; -}; - -export async function updateCustomerMaster(input: AddCustomerMasterInput) { - if (!input.phone && !input.telegramId) throw new Error('Missing phone and telegramId'); - - const { query } = await getClientWithToken(); - - const response = await query({ - query: GQL.GetCustomerMastersDocument, - variables: input, - }); - - const customer = response?.data?.customers?.at(0); - - if (customer) { - let newMastersIds = customer.masters.map((x) => x?.documentId); - - switch (input.operation) { - case 'add': - if (newMastersIds.includes(input.masterId)) return; - newMastersIds = [...newMastersIds, input.masterId]; - break; - case 'remove': - newMastersIds = newMastersIds.filter((x) => x !== input.masterId); - break; - default: - break; - } - - return updateCustomerProfile({ - documentId: customer.documentId, - data: { - masters: newMastersIds, - }, - }); - } -} - -export async function updateCustomerProfile(input: GQL.UpdateCustomerProfileMutationVariables) { - const { mutate } = await getClientWithToken(); - - return mutate({ - mutation: GQL.UpdateCustomerProfileDocument, - variables: input, - }); -} diff --git a/packages/graphql/api/customers.ts b/packages/graphql/api/customers.ts new file mode 100644 index 0000000..b63f0f7 --- /dev/null +++ b/packages/graphql/api/customers.ts @@ -0,0 +1,140 @@ +import { getClientWithToken } from '../apollo/client'; +import * as GQL from '../types'; +import { BaseService } from './base'; +import { type VariablesOf } from '@graphql-typed-document-node/core'; + +export class CustomersService extends BaseService { + async createOrUpdateCustomer(variables: VariablesOf) { + if (!variables.phone && !variables.telegramId) throw new Error('Missing phone and telegramId'); + + const { customer } = await this.getCustomer(variables); + + const { mutate } = await getClientWithToken(); + + let mutationResult; + if (customer && customer.phone === variables.phone) { + mutationResult = await mutate({ + mutation: GQL.UpdateCustomerDocument, + variables: { + data: { ...variables }, + documentId: customer.documentId, + }, + }); + } else { + mutationResult = await mutate({ + mutation: GQL.CreateCustomerDocument, + variables, + }); + } + + const error = mutationResult.errors?.at(0); + if (error) throw new Error(error.message); + + return mutationResult.data; + } + + async getCustomer(variables: VariablesOf) { + const { query } = await getClientWithToken(); + + const result = await query({ + query: GQL.GetCustomerDocument, + variables, + }); + + if (result.error) throw new Error(result.error.message); + + const customer = result.data.customers.at(0); + + return { customer }; + } + + async getCustomerClients(variables?: VariablesOf) { + const { query } = await getClientWithToken(); + + const result = await query({ + query: GQL.GetCustomerClientsDocument, + variables: { + telegramId: variables?.telegramId || this.customer.telegramId, + }, + }); + + if (result.error) throw new Error(result.error.message); + + return result.data; + } + + async getCustomerMasters(variables?: VariablesOf) { + const { query } = await getClientWithToken(); + + const result = await query({ + query: GQL.GetCustomerMastersDocument, + variables: { + telegramId: variables?.telegramId || this.customer.telegramId, + }, + }); + + if (result.error) throw new Error(result.error.message); + + return result.data; + } + + async updateCustomer( + variables: Omit, 'documentId'>, + ) { + const { customer } = await this.getCustomer(this.customer); + + if (!customer) throw new Error('Customer not found'); + const { mutate } = await getClientWithToken(); + + const mutationResult = await mutate({ + mutation: GQL.UpdateCustomerDocument, + variables: { + data: variables.data, + documentId: customer.documentId, + }, + }); + + const error = mutationResult.errors?.at(0); + if (error) throw new Error(error.message); + + return mutationResult.data; + } + + async updateCustomerMaster( + variables: VariablesOf & { + masterId: GQL.Scalars['ID']['input']; + operation: 'add' | 'remove'; + }, + ) { + if (!variables.phone && !variables.telegramId) throw new Error('Missing phone and telegramId'); + + const { query } = await getClientWithToken(); + + const response = await query({ query: GQL.GetCustomerMastersDocument, variables }); + + if (response.error) throw new Error(response.error.message); + + const customer = response?.data?.customers?.at(0); + if (!customer) throw new Error('Customer not found'); + + let newMastersIds = customer.masters.map((x) => x?.documentId); + + switch (variables.operation) { + case 'add': + if (newMastersIds.includes(variables.masterId)) break; + newMastersIds = [...newMastersIds, variables.masterId]; + break; + case 'remove': + newMastersIds = newMastersIds.filter((x) => x !== variables.masterId); + break; + default: + break; + } + + return this.updateCustomer({ + data: { + masters: newMastersIds, + }, + }); + } +} diff --git a/packages/graphql/api/index.ts b/packages/graphql/api/index.ts index 4f5a143..ae9c1ca 100644 --- a/packages/graphql/api/index.ts +++ b/packages/graphql/api/index.ts @@ -1,5 +1,5 @@ export * from './auth'; -export * from './customer'; -export * from './slot'; +export * from './customers'; export * from './order'; export * from './service'; +export * from './slot'; diff --git a/packages/graphql/eslint.config.js b/packages/graphql/eslint.config.js index e5e51e2..3fb0644 100644 --- a/packages/graphql/eslint.config.js +++ b/packages/graphql/eslint.config.js @@ -4,6 +4,6 @@ import { typescript } from '@repo/eslint-config/typescript'; export default [ ...typescript, { - ignores: ['**/graphql/types.ts', '**/schema.graphql'], + ignores: ['**/types/**'], }, ]; diff --git a/packages/graphql/operations/customer.graphql b/packages/graphql/operations/customer.graphql index b3868cf..abfcb9c 100644 --- a/packages/graphql/operations/customer.graphql +++ b/packages/graphql/operations/customer.graphql @@ -48,7 +48,7 @@ query GetCustomerClients($phone: String, $telegramId: Long) { } } -mutation UpdateCustomerProfile($documentId: ID!, $data: CustomerInput!) { +mutation UpdateCustomer($documentId: ID!, $data: CustomerInput!) { updateCustomer(documentId: $documentId, data: $data) { ...CustomerFields } diff --git a/packages/graphql/package.json b/packages/graphql/package.json index cef2fac..66199b8 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -13,15 +13,15 @@ "zod": "catalog:" }, "devDependencies": { - "graphql": "catalog:", - "@repo/eslint-config": "workspace:*", - "@repo/typescript-config": "workspace:*", - "@types/jsonwebtoken": "^9.0.7", "@graphql-codegen/cli": "^5.0.3", "@graphql-codegen/typed-document-node": "^5.0.12", "@graphql-codegen/typescript": "^4.1.2", "@graphql-codegen/typescript-operations": "^4.4.0", "@graphql-typed-document-node/core": "^3.2.0", + "@repo/eslint-config": "workspace:*", + "@repo/typescript-config": "workspace:*", + "@types/jsonwebtoken": "^9.0.7", + "graphql": "catalog:", "vite-tsconfig-paths": "catalog:", "vitest": "catalog:" } diff --git a/packages/graphql/types/operations.generated.ts b/packages/graphql/types/operations.generated.ts index c0eb19a..13ee904 100644 --- a/packages/graphql/types/operations.generated.ts +++ b/packages/graphql/types/operations.generated.ts @@ -686,13 +686,13 @@ export type GetCustomerClientsQueryVariables = Exact<{ export type GetCustomerClientsQuery = { __typename?: 'Query', customers: Array<{ __typename?: 'Customer', documentId: string, clients: Array<{ __typename?: 'Customer', active?: boolean | null | undefined, documentId: string, name: string, phone: string, photoUrl?: string | null | undefined, role: Enum_Customer_Role, telegramId?: any | null | undefined } | null | undefined> } | null | undefined> }; -export type UpdateCustomerProfileMutationVariables = Exact<{ +export type UpdateCustomerMutationVariables = Exact<{ documentId: Scalars['ID']['input']; data: CustomerInput; }>; -export type UpdateCustomerProfileMutation = { __typename?: 'Mutation', updateCustomer?: { __typename?: 'Customer', active?: boolean | null | undefined, documentId: string, name: string, phone: string, photoUrl?: string | null | undefined, role: Enum_Customer_Role, telegramId?: any | null | undefined } | null | undefined }; +export type UpdateCustomerMutation = { __typename?: 'Mutation', updateCustomer?: { __typename?: 'Customer', active?: boolean | null | undefined, documentId: string, name: string, phone: string, photoUrl?: string | null | undefined, role: Enum_Customer_Role, telegramId?: any | null | undefined } | null | undefined }; export type OrderFieldsFragment = { __typename?: 'Order', documentId: string, time_start?: any | null | undefined, time_end?: any | null | undefined, state?: Enum_Order_State | null | undefined, order_number?: number | null | undefined, services: Array<{ __typename?: 'Service', documentId: string, name?: string | null | undefined } | null | undefined>, client?: { __typename?: 'Customer', name: string, documentId: string, photoUrl?: string | null | undefined } | null | undefined }; @@ -774,7 +774,7 @@ export const CreateCustomerDocument = {"kind":"Document","definitions":[{"kind": export const GetCustomerDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCustomer"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"phone"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"telegramId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Long"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customers"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"or"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"phone"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"phone"}}}]}}]},{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"telegramId"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"telegramId"}}}]}}]}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Customer"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"active"}},{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"phone"}},{"kind":"Field","name":{"kind":"Name","value":"photoUrl"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"telegramId"}}]}}]} as unknown as DocumentNode; export const GetCustomerMastersDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCustomerMasters"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"phone"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"telegramId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Long"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customers"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"or"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"phone"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"phone"}}}]}}]},{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"telegramId"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"telegramId"}}}]}}]}]}},{"kind":"ObjectField","name":{"kind":"Name","value":"and"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"active"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"BooleanValue","value":true}}]}}]}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"masters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerFields"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Customer"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"active"}},{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"phone"}},{"kind":"Field","name":{"kind":"Name","value":"photoUrl"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"telegramId"}}]}}]} as unknown as DocumentNode; export const GetCustomerClientsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCustomerClients"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"phone"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"telegramId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Long"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customers"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"or"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"phone"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"phone"}}}]}}]},{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"telegramId"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"telegramId"}}}]}}]}]}},{"kind":"ObjectField","name":{"kind":"Name","value":"and"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"active"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"BooleanValue","value":true}}]}}]}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"clients"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerFields"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Customer"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"active"}},{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"phone"}},{"kind":"Field","name":{"kind":"Name","value":"photoUrl"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"telegramId"}}]}}]} as unknown as DocumentNode; -export const UpdateCustomerProfileDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateCustomerProfile"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"documentId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"data"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateCustomer"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"documentId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"documentId"}}},{"kind":"Argument","name":{"kind":"Name","value":"data"},"value":{"kind":"Variable","name":{"kind":"Name","value":"data"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Customer"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"active"}},{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"phone"}},{"kind":"Field","name":{"kind":"Name","value":"photoUrl"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"telegramId"}}]}}]} as unknown as DocumentNode; +export const UpdateCustomerDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateCustomer"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"documentId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"data"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateCustomer"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"documentId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"documentId"}}},{"kind":"Argument","name":{"kind":"Name","value":"data"},"value":{"kind":"Variable","name":{"kind":"Name","value":"data"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CustomerFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CustomerFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Customer"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"active"}},{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"phone"}},{"kind":"Field","name":{"kind":"Name","value":"photoUrl"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"telegramId"}}]}}]} as unknown as DocumentNode; export const GetOrderDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOrder"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"documentId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"order"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"documentId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"documentId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"OrderFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"OrderFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Order"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"time_start"}},{"kind":"Field","name":{"kind":"Name","value":"time_end"}},{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"order_number"}},{"kind":"Field","name":{"kind":"Name","value":"services"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"client"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"photoUrl"}}]}}]}}]} as unknown as DocumentNode; export const CreateOrderDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateOrder"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"OrderInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createOrder"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"data"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"OrderFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"OrderFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Order"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"time_start"}},{"kind":"Field","name":{"kind":"Name","value":"time_end"}},{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"order_number"}},{"kind":"Field","name":{"kind":"Name","value":"services"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"client"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"photoUrl"}}]}}]}}]} as unknown as DocumentNode; export const GetServicesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetServices"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"filters"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"ServiceFiltersInput"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"services"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"Variable","name":{"kind":"Name","value":"filters"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ServiceFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ServiceFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Service"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"documentId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"duration"}}]}}]} as unknown as DocumentNode; diff --git a/packages/typescript-config/base.json b/packages/typescript-config/base.json index 5117f2a..4086abd 100644 --- a/packages/typescript-config/base.json +++ b/packages/typescript-config/base.json @@ -1,8 +1,8 @@ { "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { - "declaration": true, - "declarationMap": true, + "declaration": false, + "declarationMap": false, "esModuleInterop": true, "incremental": false, "isolatedModules": true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a73f200..46f8ba2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -290,6 +290,9 @@ importers: '@graphql-typed-document-node/core': specifier: ^3.2.0 version: 3.2.0(graphql@16.9.0) + '@repo/eslint-config': + specifier: workspace:* + version: link:../eslint-config '@repo/typescript-config': specifier: workspace:* version: link:../typescript-config