feat: creats frontend for the project
This commit is contained in:
38
frontend/src/api/analytics.ts
Normal file
38
frontend/src/api/analytics.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type {
|
||||
AnalyticsSummaryParams,
|
||||
AnalyticsSummaryResponse,
|
||||
ByCategoryParams,
|
||||
ByCategoryItem,
|
||||
TimeseriesParams,
|
||||
TimeseriesItem,
|
||||
} from '@family-budget/shared';
|
||||
import { api } from './client';
|
||||
|
||||
function toQuery(params: object): string {
|
||||
const sp = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(params) as [string, unknown][]) {
|
||||
if (value != null && value !== '') {
|
||||
sp.set(key, String(value));
|
||||
}
|
||||
}
|
||||
const qs = sp.toString();
|
||||
return qs ? `?${qs}` : '';
|
||||
}
|
||||
|
||||
export async function getSummary(
|
||||
params: AnalyticsSummaryParams,
|
||||
): Promise<AnalyticsSummaryResponse> {
|
||||
return api.get(`/api/analytics/summary${toQuery(params)}`);
|
||||
}
|
||||
|
||||
export async function getByCategory(
|
||||
params: ByCategoryParams,
|
||||
): Promise<ByCategoryItem[]> {
|
||||
return api.get(`/api/analytics/by-category${toQuery(params)}`);
|
||||
}
|
||||
|
||||
export async function getTimeseries(
|
||||
params: TimeseriesParams,
|
||||
): Promise<TimeseriesItem[]> {
|
||||
return api.get(`/api/analytics/timeseries${toQuery(params)}`);
|
||||
}
|
||||
Reference in New Issue
Block a user