'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); 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, }); }