48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
'use server';
|
|
import { getClientWithToken } from '../apollo/client';
|
|
import * as GQL from '../types';
|
|
|
|
export async function createUser(variables: GQL.CreateUserMutationVariables) {
|
|
const { mutate } = await getClientWithToken();
|
|
|
|
return mutate({
|
|
mutation: GQL.CreateUserDocument,
|
|
variables,
|
|
});
|
|
}
|
|
|
|
export async function createClient(variables: GQL.CreateClientMutationVariables) {
|
|
const { mutate } = await getClientWithToken();
|
|
|
|
const response = mutate({
|
|
mutation: GQL.CreateClientDocument,
|
|
variables,
|
|
}).catch((error) => {
|
|
const isContactAlreadyExists = JSON.stringify(error).includes('This attribute must be unique');
|
|
|
|
if (isContactAlreadyExists) throw new Error('Contact already exists');
|
|
|
|
throw error;
|
|
});
|
|
|
|
return response;
|
|
}
|
|
|
|
export async function getCustomer(variables: GQL.GetCustomerQueryVariables) {
|
|
const { query } = await getClientWithToken();
|
|
|
|
return query({
|
|
query: GQL.GetCustomerDocument,
|
|
variables,
|
|
});
|
|
}
|
|
|
|
export async function updateCustomerProfile(variables: GQL.UpdateCustomerProfileMutationVariables) {
|
|
const { mutate } = await getClientWithToken();
|
|
|
|
return mutate({
|
|
mutation: GQL.UpdateCustomerProfileDocument,
|
|
variables,
|
|
});
|
|
}
|