import { cache } from 'react'; import fetchData from '@/lib/fetchData'; import { IClient } from '../types'; import { IProjectAssignment } from '../type.assignment'; import { IProject } from '../type.project'; /** * Server-side memoized data fetchers for /task and child routes. * Uses React cache() to deduplicate identical data requests across generateMetadata and Page components. * @see https://nextjs.org/docs/app/getting-started/metadata-and-og-images#memoizing-data-requests */ export const getClients = cache(async (): Promise => { return await fetchData('/client'); }); export const getClientById = cache(async (clientId: string): Promise => { return await fetchData(`/client/${clientId}`); }); export const getAssignmentsByClient = cache(async (clientId: string, queryString?: string): Promise => { const url = queryString ? `/client/project-assignment/${clientId}?${queryString}` : `/client/project-assignment/${clientId}`; return await fetchData(url); }); export const getAssignmentById = cache(async (assignmentId: string): Promise => { return await fetchData(`/project-assignment/${assignmentId}`); }); export const getProjectAssignment = cache(async (projectId: string, queryString?: string): Promise => { const url = queryString ? `/project/project-assignment/${projectId}?${queryString}` : `/project/project-assignment/${projectId}`; return await fetchData(url); });