const Customers: FunctionComponent = async () => {
const response = await getRequest("CUSTOMERS");
const customers: Customer[] = await response.json();
return <CustomerPage customers={customers} />;
};
export async function createCustomer(customer: z.infer<typeof customerSchema>) {
try {
// Send request to KV to create customer
const id = uuidv4();
// Cleanup data by removing empty objects or arrays or strings
customer = removeEmptyData(customer);
// add id to object
customer.id = id;
await putRequest("CUSTOMERS", "id:" + id, customer);
// Return success message
return {
message: "Customer created",
description: `"${customer.firstName} ${customer.name}" has been created successfully`,
success: true,
data: customer,
};
} catch (error) {
return {
message: "Error creating customer",
description: `"${customer.firstName} ${customer.name}" could not be created`,
success: false,
};
} finally {
// Revalidate cache
revalidatePath("/customers");
}
}
const Customers: FunctionComponent = async () => {
const response = await getRequest("CUSTOMERS");
const customers: Customer[] = await response.json();
return <CustomerPage customers={customers} />;
};
export async function createCustomer(customer: z.infer<typeof customerSchema>) {
try {
// Send request to KV to create customer
const id = uuidv4();
// Cleanup data by removing empty objects or arrays or strings
customer = removeEmptyData(customer);
// add id to object
customer.id = id;
await putRequest("CUSTOMERS", "id:" + id, customer);
// Return success message
return {
message: "Customer created",
description: `"${customer.firstName} ${customer.name}" has been created successfully`,
success: true,
data: customer,
};
} catch (error) {
return {
message: "Error creating customer",
description: `"${customer.firstName} ${customer.name}" could not be created`,
success: false,
};
} finally {
// Revalidate cache
revalidatePath("/customers");
}
}