From 35134e9663c05171f8d0cf0c7b44e92974e13659 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 16 May 2025 20:06:09 +0300 Subject: [PATCH] fix telegramId type (number) --- apps/web/app/(auth)/browser/page.tsx | 2 +- apps/web/app/(auth)/telegram/page.tsx | 2 +- apps/web/app/(main)/profile/[telegramId]/page.tsx | 2 +- apps/web/components/profile/types.tsx | 2 +- apps/web/config/auth.ts | 2 +- apps/web/mocks/get-telegram-user.ts | 2 +- apps/web/types/next-auth.d.ts | 4 ++-- packages/graphql/api/base.ts | 2 +- packages/graphql/graphql.config.cjs | 5 ++++- packages/graphql/types/operations.generated.ts | 12 ++++++------ 10 files changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/web/app/(auth)/browser/page.tsx b/apps/web/app/(auth)/browser/page.tsx index a989110..e7a5d2e 100644 --- a/apps/web/app/(auth)/browser/page.tsx +++ b/apps/web/app/(auth)/browser/page.tsx @@ -21,7 +21,7 @@ export default function Auth() { signIn('telegram', { callbackUrl: '/profile', redirect: false, - telegramId: String(user?.id), + telegramId: user?.id, }); }); } diff --git a/apps/web/app/(auth)/telegram/page.tsx b/apps/web/app/(auth)/telegram/page.tsx index 36e24d1..9d0c08f 100644 --- a/apps/web/app/(auth)/telegram/page.tsx +++ b/apps/web/app/(auth)/telegram/page.tsx @@ -28,7 +28,7 @@ function useAuth() { signIn('telegram', { callbackUrl: '/profile', redirect: false, - telegramId: String(initDataUser.id), + telegramId: initDataUser.id, }).then(() => redirect('/profile')); } }, [initDataUser?.id, status]); diff --git a/apps/web/app/(main)/profile/[telegramId]/page.tsx b/apps/web/app/(main)/profile/[telegramId]/page.tsx index dac16f6..8f1e663 100644 --- a/apps/web/app/(main)/profile/[telegramId]/page.tsx +++ b/apps/web/app/(main)/profile/[telegramId]/page.tsx @@ -7,7 +7,7 @@ type Props = { params: Promise<{ telegramId: string }> }; export default async function ProfilePage(props: Readonly) { const parameters = await props.params; - const { telegramId } = parameters; + const telegramId = Number.parseInt(parameters.telegramId, 10); const queryClient = new QueryClient(); diff --git a/apps/web/components/profile/types.tsx b/apps/web/components/profile/types.tsx index 974e69f..3090f9a 100644 --- a/apps/web/components/profile/types.tsx +++ b/apps/web/components/profile/types.tsx @@ -1,3 +1,3 @@ export type ProfileProps = { - readonly telegramId?: string; + readonly telegramId?: number; }; diff --git a/apps/web/config/auth.ts b/apps/web/config/auth.ts index 3846dcb..d7e9522 100644 --- a/apps/web/config/auth.ts +++ b/apps/web/config/auth.ts @@ -12,7 +12,7 @@ export const authOptions: AuthOptions = { }, async session({ session, token }) { if (token?.id && session?.user) { - session.user.telegramId = token.id as string; + session.user.telegramId = token.id as number; } return session; diff --git a/apps/web/mocks/get-telegram-user.ts b/apps/web/mocks/get-telegram-user.ts index 1516fd5..f05cb73 100644 --- a/apps/web/mocks/get-telegram-user.ts +++ b/apps/web/mocks/get-telegram-user.ts @@ -5,7 +5,7 @@ import { env } from '@/config/env'; export async function getTelegramUser() { if (process.env.NODE_ENV !== 'production') return { - id: env.__DEV_TELEGRAM_ID, + id: Number.parseInt(env.__DEV_TELEGRAM_ID, 10), }; return null; diff --git a/apps/web/types/next-auth.d.ts b/apps/web/types/next-auth.d.ts index 9bf0e89..4dcef7c 100644 --- a/apps/web/types/next-auth.d.ts +++ b/apps/web/types/next-auth.d.ts @@ -4,11 +4,11 @@ import { type DefaultSession } from 'next-auth'; declare module 'next-auth' { interface Session extends DefaultSession { user?: { - telegramId?: null | string; + telegramId?: null | number; }; } interface User extends DefaultUser { - telegramId?: null | string; + telegramId?: null | number; } } diff --git a/packages/graphql/api/base.ts b/packages/graphql/api/base.ts index c76043a..f2531bd 100644 --- a/packages/graphql/api/base.ts +++ b/packages/graphql/api/base.ts @@ -1,5 +1,5 @@ type CustomerProfile = { - telegramId: string; + telegramId: number; }; export class BaseService { diff --git a/packages/graphql/graphql.config.cjs b/packages/graphql/graphql.config.cjs index c1d69b9..f575ce9 100644 --- a/packages/graphql/graphql.config.cjs +++ b/packages/graphql/graphql.config.cjs @@ -5,9 +5,12 @@ module.exports = { './types/operations.generated.ts': { config: { avoidOptionals: false, + maybeValue: 'T | null | undefined', onlyOperationTypes: true, + scalars: { + Long: 'number', + }, useTypeImports: true, - maybeValue: 'T | null | undefined' }, plugins: ['typescript', 'typescript-operations', 'typed-document-node'], }, diff --git a/packages/graphql/types/operations.generated.ts b/packages/graphql/types/operations.generated.ts index 13ee904..587b88c 100644 --- a/packages/graphql/types/operations.generated.ts +++ b/packages/graphql/types/operations.generated.ts @@ -16,7 +16,7 @@ export type Scalars = { Date: { input: any; output: any; } DateTime: { input: any; output: any; } JSON: { input: any; output: any; } - Long: { input: any; output: any; } + Long: { input: number; output: number; } Time: { input: any; output: any; } }; @@ -651,7 +651,7 @@ export type LoginMutationVariables = Exact<{ export type LoginMutation = { __typename?: 'Mutation', login: { __typename?: 'UsersPermissionsLoginPayload', jwt?: string | null | undefined } }; -export type CustomerFieldsFragment = { __typename?: 'Customer', active?: boolean | null | undefined, documentId: string, name: string, phone: string, photoUrl?: string | null | undefined, role: Enum_Customer_Role, telegramId?: any | null | undefined }; +export type CustomerFieldsFragment = { __typename?: 'Customer', active?: boolean | null | undefined, documentId: string, name: string, phone: string, photoUrl?: string | null | undefined, role: Enum_Customer_Role, telegramId?: number | null | undefined }; export type CreateCustomerMutationVariables = Exact<{ name: Scalars['String']['input']; @@ -668,7 +668,7 @@ export type GetCustomerQueryVariables = Exact<{ }>; -export type GetCustomerQuery = { __typename?: 'Query', customers: 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> }; +export type GetCustomerQuery = { __typename?: 'Query', customers: Array<{ __typename?: 'Customer', active?: boolean | null | undefined, documentId: string, name: string, phone: string, photoUrl?: string | null | undefined, role: Enum_Customer_Role, telegramId?: number | null | undefined } | null | undefined> }; export type GetCustomerMastersQueryVariables = Exact<{ phone?: InputMaybe; @@ -676,7 +676,7 @@ export type GetCustomerMastersQueryVariables = Exact<{ }>; -export type GetCustomerMastersQuery = { __typename?: 'Query', customers: Array<{ __typename?: 'Customer', documentId: string, masters: 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 GetCustomerMastersQuery = { __typename?: 'Query', customers: Array<{ __typename?: 'Customer', documentId: string, masters: Array<{ __typename?: 'Customer', active?: boolean | null | undefined, documentId: string, name: string, phone: string, photoUrl?: string | null | undefined, role: Enum_Customer_Role, telegramId?: number | null | undefined } | null | undefined> } | null | undefined> }; export type GetCustomerClientsQueryVariables = Exact<{ phone?: InputMaybe; @@ -684,7 +684,7 @@ 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 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?: number | null | undefined } | null | undefined> } | null | undefined> }; export type UpdateCustomerMutationVariables = Exact<{ documentId: Scalars['ID']['input']; @@ -692,7 +692,7 @@ export type UpdateCustomerMutationVariables = Exact<{ }>; -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 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?: number | 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 };