-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move getTaskTypes, getProjects and getTemplates to factory pattern
- Loading branch information
1 parent
9493bf9
commit 8a686e1
Showing
5 changed files
with
26 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Array<Template>> => { | ||
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<Array<Template>> => { | ||
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() | ||
} |