29 lines
840 B
TypeScript
29 lines
840 B
TypeScript
'use server';
|
|
import { authOptions } from '@/config/auth';
|
|
import { getCustomer, updateCustomerProfile } from '@repo/graphql/api';
|
|
import { type CustomerInput } from '@repo/graphql/types';
|
|
import { getServerSession } from 'next-auth/next';
|
|
import { revalidatePath } from 'next/cache';
|
|
|
|
export async function becomeMaster() {
|
|
revalidatePath('/profile');
|
|
}
|
|
|
|
export async function updateProfile(input: CustomerInput) {
|
|
const session = await getServerSession(authOptions);
|
|
|
|
if (session) {
|
|
const { user } = session;
|
|
const getCustomerResponse = await getCustomer({ telegramId: user?.telegramId });
|
|
const customer = getCustomerResponse.data.customers.at(0);
|
|
if (customer) {
|
|
await updateCustomerProfile({
|
|
data: input,
|
|
documentId: customer.documentId,
|
|
});
|
|
}
|
|
}
|
|
|
|
revalidatePath('/profile');
|
|
}
|