'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'; import { revalidatePath } from 'next/cache'; 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 customer = await getCustomer({ telegramId }); return customer; } export async function updateProfile(input: CustomerInput) { const session = await getServerSession(authOptions); if (!session) throw new Error('Missing session'); const { user } = session; const customer = await getCustomer({ telegramId: user?.telegramId }); if (!customer) throw new Error('Customer not found'); await updateCustomerProfile({ data: input, documentId: customer.documentId, }); revalidatePath('/profile'); }