- Remove `CustomerRepository` and its methods for customer management and caching. - Refactor customer-related pages (`[id]/page.tsx`, `customers/page.tsx`) to use direct `fetch` API calls. - Update breadcrumb resolver to fetch data directly from the API. - Simplify `addCustomer` use case to avoid repository dependency.
31 lines
786 B
TypeScript
31 lines
786 B
TypeScript
"use server";
|
|
|
|
import {CreateCustomerDto} from "@/services/customers/dtos/createCustomer.dto";
|
|
|
|
export async function addCustomer(params: CreateCustomerDto): Promise<void> {
|
|
const {email, name, companyName, street, zip, city, phoneNumbers, notes} = params;
|
|
|
|
const payload: CreateCustomerDto = {
|
|
email,
|
|
name,
|
|
companyName,
|
|
street,
|
|
zip,
|
|
city,
|
|
phoneNumbers,
|
|
notes: notes.map(({text}) => ({text})),
|
|
};
|
|
|
|
const response = await fetch('/api/customers', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(payload)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to create customer: ${response.statusText}`);
|
|
}
|
|
}
|