diff --git a/frontend/src/app/planner/page.tsx b/frontend/src/app/planner/page.tsx index cc8a9ad31..6e3775d96 100644 --- a/frontend/src/app/planner/page.tsx +++ b/frontend/src/app/planner/page.tsx @@ -1,11 +1,12 @@ -import { getProjects } from '@/infra/project/getProjects' +import { makeGetProjects } from '@/infra/project/getProjects' import { serverFetch } from '@/infra/lib/serverFetch' import { ProjectSelection } from './components/ProjectSelection' const getPageData = async () => { const apiClient = await serverFetch() + const getProjects = makeGetProjects(apiClient) - return getProjects(apiClient) + return getProjects() } export default async function ProjectManagement() { diff --git a/frontend/src/app/tasks/page.tsx b/frontend/src/app/tasks/page.tsx index 0ad189e3a..4c11f651a 100644 --- a/frontend/src/app/tasks/page.tsx +++ b/frontend/src/app/tasks/page.tsx @@ -1,21 +1,21 @@ import { DayView } from './DayView' -import { getProjects } from '@/infra/project/getProjects' -import { getTaskTypes } from '@/infra/taskType/getTaskTypes' +import { makeGetProjects } from '@/infra/project/getProjects' +import { makeGetTaskTypes } from '@/infra/taskType/getTaskTypes' +import { makeGetTemplates } from '@/infra/template/getTemplates' import { serverFetch } from '@/infra/lib/serverFetch' import { authOptions } from '@/app/api/auth/[...nextauth]/route' import { getServerSession } from 'next-auth' -import { getTemplates } from '@/infra/template/getTemplates' const getPageData = async () => { const apiClient = await serverFetch() const session = await getServerSession(authOptions) const { id: userId } = session!.user - return await Promise.all([ - getProjects(apiClient), - getTaskTypes(apiClient), - getTemplates(apiClient, { userId }) - ]) + const getProjects = makeGetProjects(apiClient) + const getTaskTypes = makeGetTaskTypes(apiClient) + const getTemplates = makeGetTemplates(apiClient) + + return await Promise.all([getProjects(), getTaskTypes(), getTemplates({ userId })]) } export default async function Tasks() { diff --git a/frontend/src/infra/project/getProjects.ts b/frontend/src/infra/project/getProjects.ts index fb0f73b21..6d0eafc68 100644 --- a/frontend/src/infra/project/getProjects.ts +++ b/frontend/src/infra/project/getProjects.ts @@ -1,7 +1,7 @@ import { ApiClient } from '@/infra/lib/apiClient' import { Project } from '@/domain/Project' -export const getProjects = async (apiClient: ApiClient): Promise> => { +export const makeGetProjects = (apiClient: ApiClient) => async (): Promise> => { const response = await apiClient('/v1/projects/') if (!response.ok) { diff --git a/frontend/src/infra/taskType/getTaskTypes.ts b/frontend/src/infra/taskType/getTaskTypes.ts index 46e14c2ab..7b88701ef 100644 --- a/frontend/src/infra/taskType/getTaskTypes.ts +++ b/frontend/src/infra/taskType/getTaskTypes.ts @@ -1,7 +1,7 @@ import { ApiClient } from '@/infra/lib/apiClient' import { TaskType } from '@/domain/TaskType' -export const getTaskTypes = async (apiClient: ApiClient): Promise> => { +export const makeGetTaskTypes = (apiClient: ApiClient) => async (): Promise> => { const response = await apiClient('/v1/timelog/task_types/') if (!response.ok) { diff --git a/frontend/src/infra/template/getTemplates.ts b/frontend/src/infra/template/getTemplates.ts index 1112ff907..8dfb06cf3 100644 --- a/frontend/src/infra/template/getTemplates.ts +++ b/frontend/src/infra/template/getTemplates.ts @@ -1,18 +1,18 @@ import { Template } from '@/domain/Template' import { ApiClient } from '../lib/apiClient' +import { User } from '@/domain/User' -export const getTemplates = async ( - apiClient: ApiClient, - { userId }: { userId: number } -): Promise> => { - const params = new URLSearchParams({ user_id: userId.toString() }) - const response = await apiClient(`/v1/timelog/templates?${params}`, { - next: { tags: ['templates'] } - }) +export const makeGetTemplates = + (apiClient: ApiClient) => + async ({ userId }: { userId: User['id'] }): Promise> => { + const params = new URLSearchParams({ user_id: userId.toString() }) + const response = await apiClient(`/v1/timelog/templates?${params}`, { + next: { tags: ['templates'] } + }) - if (!response.ok) { - throw new Error('Failed to fetch Templates') - } + if (!response.ok) { + throw new Error('Failed to fetch Templates') + } - return await response.json() -} + return await response.json() + }