beautify actions
This commit is contained in:
parent
7652ca9bb4
commit
d00f8475f2
@ -5,30 +5,25 @@ import { getServerSession } from 'next-auth/next';
|
||||
|
||||
export async function getClients() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) throw new Error('Missing session');
|
||||
|
||||
if (session) {
|
||||
const { user } = session;
|
||||
const getCustomerClientsResponse = await getCustomerClients({ telegramId: user?.telegramId });
|
||||
const { user } = session;
|
||||
|
||||
return {
|
||||
clients: getCustomerClientsResponse?.clients,
|
||||
};
|
||||
}
|
||||
const getCustomerClientsResponse = await getCustomerClients({ telegramId: user?.telegramId });
|
||||
|
||||
return null;
|
||||
return {
|
||||
clients: getCustomerClientsResponse?.clients,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getMasters() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) throw new Error('Missing session');
|
||||
|
||||
if (session) {
|
||||
const { user } = session;
|
||||
const getCustomerMastersResponse = await getCustomerMasters({ telegramId: user?.telegramId });
|
||||
const { user } = session;
|
||||
const getCustomerMastersResponse = await getCustomerMasters({ telegramId: user?.telegramId });
|
||||
|
||||
return {
|
||||
masters: getCustomerMastersResponse?.masters,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
return {
|
||||
masters: getCustomerMastersResponse?.masters,
|
||||
};
|
||||
}
|
||||
|
||||
@ -7,31 +7,26 @@ import { revalidatePath } from 'next/cache';
|
||||
|
||||
export async function getProfile() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) throw new Error('Missing session');
|
||||
|
||||
if (session) {
|
||||
const { user } = session;
|
||||
const customer = await getCustomer({ telegramId: user?.telegramId });
|
||||
if (customer) {
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
const { user } = session;
|
||||
const customer = await getCustomer({ telegramId: user?.telegramId });
|
||||
return customer;
|
||||
}
|
||||
|
||||
export async function updateProfile(input: CustomerInput) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) throw new Error('Missing session');
|
||||
|
||||
if (session) {
|
||||
const { user } = session;
|
||||
const customer = await getCustomer({ telegramId: user?.telegramId });
|
||||
if (customer) {
|
||||
await updateCustomerProfile({
|
||||
data: input,
|
||||
documentId: customer.documentId,
|
||||
});
|
||||
}
|
||||
}
|
||||
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');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user