From ac086d73f880597de54f2720daf39c3719d111c7 Mon Sep 17 00:00:00 2001 From: Wayne Date: Wed, 27 Mar 2024 23:11:54 +0900 Subject: [PATCH] Use projections for project search --- src/app/api/projects/index.ts | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/app/api/projects/index.ts b/src/app/api/projects/index.ts index 82440a9..8374721 100644 --- a/src/app/api/projects/index.ts +++ b/src/app/api/projects/index.ts @@ -2,20 +2,6 @@ import { serverFetchJson } from "@/app/utils/fetchUtil"; import { BASE_API_URL } from "@/config/api"; import { cache } from "react"; 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 { id: number; @@ -37,24 +23,9 @@ export const preloadProjects = () => { }; export const fetchProjects = cache(async () => { - const projects = await serverFetchJson( - `${BASE_API_URL}/projects`, - { - next: { tags: ["projects"] }, - }, - ); - - // TODO: Replace this with a project - return projects.map( - ({ id, code, name, projectCategory, teamLead, customer }) => ({ - id, - code, - name, - category: projectCategory.name, - team: teamLead.team.code, - client: customer.name, - }), - ); + return serverFetchJson(`${BASE_API_URL}/projects`, { + next: { tags: ["projects"] }, + }); }); export const fetchProjectCategories = cache(async () => {