Skip to content

Commit

Permalink
Add getProjectStats fetch request
Browse files Browse the repository at this point in the history
  • Loading branch information
anarute committed Jan 18, 2024
1 parent 3472f9a commit b9da1fb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions frontend/src/infra/project/getProjectStats.ts
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()
}

0 comments on commit b9da1fb

Please sign in to comment.