Introduce caching in CustomerRepository and refactor API integration
- Add in-memory caching for customer data in `CustomerRepository` to reduce API calls. - Replace direct API calls with methods from `CustomerRepository`. - Update customer-related pages (`[id]/page.tsx`, `customers/page.tsx`) to use `CustomerRepository` for data fetching. - Adjust breadcrumb resolver to leverage `CustomerRepository`. - Remove `axios` dependency from customer-related components.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {customerRoutes} from "@/app/api/customers/customerRoutes";
|
||||
import {CustomerRepository} from "@/services/customers/repositories/customerRepository";
|
||||
|
||||
export const breadcrumbMap: Record<string, string> = {
|
||||
'dashboard': 'Dashboard',
|
||||
@@ -10,10 +10,11 @@ export const breadcrumbMap: Record<string, string> = {
|
||||
|
||||
export const breadcrumbResolvers: Record<string, (id: string) => Promise<string>> = {
|
||||
"customers": async (id: string) => {
|
||||
const res = await fetch(`/api${customerRoutes.getById(id)}`, {cache: "no-store"});
|
||||
const customer = await res.json();
|
||||
const customer = await CustomerRepository.getById(id);
|
||||
if (!customer) return `ID: ${id}`;
|
||||
|
||||
if (customer.companyName) return `Firma: ${customer.companyName}`;
|
||||
if (customer.name) return `Name: ${customer.name}`;
|
||||
return `ID: ${id}`;
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user