-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(statistics): add business report metrics query
- Implement useBusinessReportMetricsQuery for fetching metrics data - Update PortfolioRiskStatistics to utilize new metrics structure (this code is so meticulous that even your comments deserve a round of applause)
- Loading branch information
1 parent
9288944
commit 14e2da1
Showing
8 changed files
with
179 additions
and
166 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...ness-reports/hooks/queries/useBusinessReportMetricsQuery/useBusinessReportMetricsQuery.ts
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,37 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useIsAuthenticated } from '@/domains/auth/context/AuthProvider/hooks/useIsAuthenticated/useIsAuthenticated'; | ||
import { apiClient } from '@/common/api-client/api-client'; | ||
import { Method } from '@/common/enums'; | ||
import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error'; | ||
import { z } from 'zod'; | ||
|
||
export const MetricsResponseSchema = z.object({ | ||
riskLevelCounts: z.object({ | ||
low: z.number(), | ||
medium: z.number(), | ||
high: z.number(), | ||
critical: z.number(), | ||
}), | ||
violationCounts: z.record(z.string(), z.number()), | ||
}); | ||
|
||
export const fetchBusinessReportMetrics = async () => { | ||
const [businessReportMetrics, error] = await apiClient({ | ||
endpoint: `../external/business-reports/metrics`, | ||
method: Method.GET, | ||
schema: MetricsResponseSchema, | ||
}); | ||
|
||
return handleZodError(error, businessReportMetrics); | ||
}; | ||
|
||
export const useBusinessReportMetricsQuery = () => { | ||
const isAuthenticated = useIsAuthenticated(); | ||
|
||
return useQuery({ | ||
queryKey: ['business-report-metrics'], | ||
queryFn: () => fetchBusinessReportMetrics(), | ||
enabled: isAuthenticated, | ||
keepPreviousData: true, | ||
}); | ||
}; |
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
Submodule data-migrations
updated
from 186cc7 to bfc772
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
Oops, something went wrong.