Files
LaDOSE/LaDOSE.Src/LaDOSE.WebApp/src/lib/api/statistics.ts
T
2026-08-06 09:58:06 +02:00

30 lines
1.1 KiB
TypeScript

import { session } from '$lib/stores/session.svelte';
import { apiRequest, type RequestOptions } from './client';
import type { MatchStatsDTO } from './schema-helpers';
/** StatisticsController is `[Authorize]`, like the tournament endpoints. */
function authed(options: RequestOptions): RequestOptions {
return { ...options, token: options.token ?? session.token };
}
/**
* POST /api/Statistics/Matches — set-level statistics (win/loss, games, head to
* head) for the given events, read from the `set` rows an import persisted.
*
* Unlike `GetResults` this takes every event in one call: the service tolerates
* brackets with no set rows instead of throwing, and reports what it could see in
* `coverage`. Always show that coverage — many older brackets were imported
* without sets, so a low `bracketsWithSets` means these numbers describe only a
* slice of the scope.
*/
export function getMatchStats(
eventIds: number[],
options: RequestOptions = {}
): Promise<MatchStatsDTO> {
return apiRequest<MatchStatsDTO>('/api/Statistics/Matches', {
...authed(options),
method: 'POST',
body: eventIds
});
}