mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 17:56:28 +00:00
de8d463b97
Relocate the task query module and update its type and route imports to use the new `utils/queries` path.
34 lines
1.5 KiB
TypeScript
34 lines
1.5 KiB
TypeScript
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<IClient[]> => {
|
|
return await fetchData('/client');
|
|
});
|
|
|
|
export const getClientById = cache(async (clientId: string): Promise<IClient> => {
|
|
return await fetchData(`/client/${clientId}`);
|
|
});
|
|
|
|
export const getAssignmentsByClient = cache(async (clientId: string, queryString?: string): Promise<IProjectAssignment[]> => {
|
|
const url = queryString ? `/client/project-assignment/${clientId}?${queryString}` : `/client/project-assignment/${clientId}`;
|
|
return await fetchData(url);
|
|
});
|
|
|
|
export const getAssignmentById = cache(async (assignmentId: string): Promise<IProjectAssignment> => {
|
|
return await fetchData(`/project-assignment/${assignmentId}`);
|
|
});
|
|
|
|
export const getProjectAssignment = cache(async (projectId: string, queryString?: string): Promise<IProject> => {
|
|
const url = queryString ? `/project/project-assignment/${projectId}?${queryString}` : `/project/project-assignment/${projectId}`;
|
|
return await fetchData(url);
|
|
});
|