|
- import { serverFetchJson } from "@/app/utils/fetchUtil";
- import { BASE_API_URL } from "@/config/api";
- import { cache } from "react";
- import "server-only";
- import { Task, TaskGroup } from "../tasks";
-
- export interface ProjectResult {
- id: number;
- code: string;
- name: string;
- category: string;
- team: string;
- client: string;
- }
-
- export interface ProjectCategory {
- id: number;
- name: string;
- }
-
- export interface ServiceType {
- id: number;
- name: string;
- }
-
- export interface FundingType {
- id: number;
- name: string;
- }
-
- export interface ContractType {
- id: number;
- name: string;
- }
-
- export interface LocationType {
- id: number;
- name: string;
- }
-
- export interface BuildingType {
- id: number;
- name: string;
- }
-
- export interface WorkNature {
- id: number;
- name: string;
- }
-
- export interface AssignedProject {
- id: number;
- code: string;
- name: string;
- tasks: Task[];
- milestones: {
- [taskGroupId: TaskGroup["id"]]: {
- startDate: string;
- endDate: string;
- };
- };
- }
-
- export const preloadProjects = () => {
- fetchProjectCategories();
- fetchProjects();
- };
-
- export const fetchProjects = cache(async () => {
- return serverFetchJson<ProjectResult[]>(`${BASE_API_URL}/projects`, {
- next: { tags: ["projects"] },
- });
- });
-
- export const fetchProjectCategories = cache(async () => {
- return serverFetchJson<ProjectCategory[]>(
- `${BASE_API_URL}/projects/categories`,
- {
- next: { tags: ["projectCategories"] },
- },
- );
- });
-
- export const fetchProjectServiceTypes = cache(async () => {
- return serverFetchJson<ServiceType[]>(
- `${BASE_API_URL}/projects/serviceTypes`,
- {
- next: { tags: ["projectServiceTypes"] },
- },
- );
- });
-
- export const fetchProjectFundingTypes = cache(async () => {
- return serverFetchJson<FundingType[]>(
- `${BASE_API_URL}/projects/fundingTypes`,
- {
- next: { tags: ["projectFundingTypes"] },
- },
- );
- });
-
- export const fetchProjectContractTypes = cache(async () => {
- return serverFetchJson<ContractType[]>(
- `${BASE_API_URL}/projects/contractTypes`,
- {
- next: { tags: ["projectContractTypes"] },
- },
- );
- });
-
- export const fetchProjectLocationTypes = cache(async () => {
- return serverFetchJson<LocationType[]>(
- `${BASE_API_URL}/projects/locationTypes`,
- {
- next: { tags: ["projectLocationTypes"] },
- },
- );
- });
-
- export const fetchProjectBuildingTypes = cache(async () => {
- return serverFetchJson<BuildingType[]>(
- `${BASE_API_URL}/projects/buildingTypes`,
- {
- next: { tags: ["projectBuildingTypes"] },
- },
- );
- });
-
- export const fetchProjectWorkNatures = cache(async () => {
- return serverFetchJson<WorkNature[]>(`${BASE_API_URL}/projects/workNatures`, {
- next: { tags: ["projectWorkNatures"] },
- });
- });
|