Просмотр исходного кода

Use projections for project search

tags/Baseline_30082024_FRONTEND_UAT
Wayne 1 год назад
Родитель
Сommit
ac086d73f8
1 измененных файлов: 3 добавлений и 32 удалений
  1. +3
    -32
      src/app/api/projects/index.ts

+ 3
- 32
src/app/api/projects/index.ts Просмотреть файл

@@ -2,20 +2,6 @@ import { serverFetchJson } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api"; import { BASE_API_URL } from "@/config/api";
import { cache } from "react"; import { cache } from "react";
import "server-only"; import "server-only";
import { Staff } from "../staff";

interface Project {
id: number;
code: string;
name: string;
projectCategory: {
name: string;
};
teamLead: Staff;
customer: {
name: string;
};
}


export interface ProjectResult { export interface ProjectResult {
id: number; id: number;
@@ -37,24 +23,9 @@ export const preloadProjects = () => {
}; };


export const fetchProjects = cache(async () => { export const fetchProjects = cache(async () => {
const projects = await serverFetchJson<Project[]>(
`${BASE_API_URL}/projects`,
{
next: { tags: ["projects"] },
},
);

// TODO: Replace this with a project
return projects.map<ProjectResult>(
({ id, code, name, projectCategory, teamLead, customer }) => ({
id,
code,
name,
category: projectCategory.name,
team: teamLead.team.code,
client: customer.name,
}),
);
return serverFetchJson<ProjectResult[]>(`${BASE_API_URL}/projects`, {
next: { tags: ["projects"] },
});
}); });


export const fetchProjectCategories = cache(async () => { export const fetchProjectCategories = cache(async () => {


Загрузка…
Отмена
Сохранить