introduce zod schemas
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
import { fetchServerAPI } from './base';
|
||||
import type { StateHistoryStats } from '@/lib/types/statistics';
|
||||
import {
|
||||
StateHistoryStatsFilter,
|
||||
stateHistoryStatsFilterSchema,
|
||||
stateHistoryStatsSchema,
|
||||
type StateHistoryStats
|
||||
} from '@/lib/schemas/statistics';
|
||||
|
||||
const serverRoute = '/server';
|
||||
|
||||
export async function getServerStatistics(
|
||||
token: string,
|
||||
serverId: string,
|
||||
startDate: string,
|
||||
endDate: string
|
||||
filters: StateHistoryStatsFilter
|
||||
): Promise<StateHistoryStats> {
|
||||
const { startDate, endDate } = stateHistoryStatsFilterSchema.parse(filters);
|
||||
const response = await fetchServerAPI<StateHistoryStats>(
|
||||
`${serverRoute}/${serverId}/state-history/statistics?start_date=${startDate}&end_date=${endDate}`,
|
||||
token
|
||||
);
|
||||
return response.data!;
|
||||
return stateHistoryStatsSchema.parse(response.data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user