2025-01-12 16:04:10 +03:00

43 lines
1.1 KiB
TypeScript

'use server';
import { authOptions } from '@/config/auth';
import { getCustomer, updateCustomerProfile } from '@repo/graphql/api';
import { type CustomerInput, type Enum_Customer_Role } from '@repo/graphql/types';
import { getServerSession } from 'next-auth/next';
import { revalidatePath } from 'next/cache';
export async function updateProfile(input: CustomerInput) {
const session = await getServerSession(authOptions);
if (session) {
const { user } = session;
const customer = await getCustomer({ telegramId: user?.telegramId });
if (customer) {
await updateCustomerProfile({
data: input,
documentId: customer.documentId,
});
}
}
revalidatePath('/profile');
}
export async function updateRole(role: Enum_Customer_Role) {
const session = await getServerSession(authOptions);
if (session) {
const { user } = session;
const customer = await getCustomer({ telegramId: user?.telegramId });
if (customer) {
await updateCustomerProfile({
data: {
role,
},
documentId: customer.documentId,
});
}
}
revalidatePath('/profile');
}