You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

134 lines
2.7 KiB

  1. import { serverFetchJson } from "@/app/utils/fetchUtil";
  2. import { BASE_API_URL } from "@/config/api";
  3. import { cache } from "react";
  4. import "server-only";
  5. import { Task, TaskGroup } from "../tasks";
  6. export interface ProjectResult {
  7. id: number;
  8. code: string;
  9. name: string;
  10. category: string;
  11. team: string;
  12. client: string;
  13. }
  14. export interface ProjectCategory {
  15. id: number;
  16. name: string;
  17. }
  18. export interface ServiceType {
  19. id: number;
  20. name: string;
  21. }
  22. export interface FundingType {
  23. id: number;
  24. name: string;
  25. }
  26. export interface ContractType {
  27. id: number;
  28. name: string;
  29. }
  30. export interface LocationType {
  31. id: number;
  32. name: string;
  33. }
  34. export interface BuildingType {
  35. id: number;
  36. name: string;
  37. }
  38. export interface WorkNature {
  39. id: number;
  40. name: string;
  41. }
  42. export interface AssignedProject {
  43. id: number;
  44. code: string;
  45. name: string;
  46. tasks: Task[];
  47. milestones: {
  48. [taskGroupId: TaskGroup["id"]]: {
  49. startDate: string;
  50. endDate: string;
  51. };
  52. };
  53. }
  54. export const preloadProjects = () => {
  55. fetchProjectCategories();
  56. fetchProjects();
  57. };
  58. export const fetchProjects = cache(async () => {
  59. return serverFetchJson<ProjectResult[]>(`${BASE_API_URL}/projects`, {
  60. next: { tags: ["projects"] },
  61. });
  62. });
  63. export const fetchProjectCategories = cache(async () => {
  64. return serverFetchJson<ProjectCategory[]>(
  65. `${BASE_API_URL}/projects/categories`,
  66. {
  67. next: { tags: ["projectCategories"] },
  68. },
  69. );
  70. });
  71. export const fetchProjectServiceTypes = cache(async () => {
  72. return serverFetchJson<ServiceType[]>(
  73. `${BASE_API_URL}/projects/serviceTypes`,
  74. {
  75. next: { tags: ["projectServiceTypes"] },
  76. },
  77. );
  78. });
  79. export const fetchProjectFundingTypes = cache(async () => {
  80. return serverFetchJson<FundingType[]>(
  81. `${BASE_API_URL}/projects/fundingTypes`,
  82. {
  83. next: { tags: ["projectFundingTypes"] },
  84. },
  85. );
  86. });
  87. export const fetchProjectContractTypes = cache(async () => {
  88. return serverFetchJson<ContractType[]>(
  89. `${BASE_API_URL}/projects/contractTypes`,
  90. {
  91. next: { tags: ["projectContractTypes"] },
  92. },
  93. );
  94. });
  95. export const fetchProjectLocationTypes = cache(async () => {
  96. return serverFetchJson<LocationType[]>(
  97. `${BASE_API_URL}/projects/locationTypes`,
  98. {
  99. next: { tags: ["projectLocationTypes"] },
  100. },
  101. );
  102. });
  103. export const fetchProjectBuildingTypes = cache(async () => {
  104. return serverFetchJson<BuildingType[]>(
  105. `${BASE_API_URL}/projects/buildingTypes`,
  106. {
  107. next: { tags: ["projectBuildingTypes"] },
  108. },
  109. );
  110. });
  111. export const fetchProjectWorkNatures = cache(async () => {
  112. return serverFetchJson<WorkNature[]>(`${BASE_API_URL}/projects/workNatures`, {
  113. next: { tags: ["projectWorkNatures"] },
  114. });
  115. });