-
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.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { format } from 'date-fns' | ||
import { ApiClient } from '@/infra/lib/apiClient' | ||
|
||
export const makeGetProjectStats = | ||
(apiClient: ApiClient) => | ||
async (projectId: string): Promise<any> => { | ||
const today = new Date() | ||
// TODO start getting the date range dynamically | ||
const firstDayOfYear = new Date(today.getFullYear(), 0, 1) | ||
const lastDayOfYear = new Date(today.getFullYear(), 11, 31) | ||
|
||
const params = new URLSearchParams({ | ||
start: format(firstDayOfYear, 'yyyy-MM-dd'), | ||
end: format(lastDayOfYear, 'yyyy-MM-dd') | ||
}) | ||
const response = await apiClient(`/v1/projects/${projectId}/stats?${params}`) | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch Project Statistics') | ||
} | ||
|
||
return await response.json() | ||
} |