mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-05 03:02:56 +00:00
dev day #89
This commit is contained in:
@@ -44,8 +44,15 @@ function normalize(p: any): Player {
|
||||
} as Player;
|
||||
}
|
||||
|
||||
export async function getPlayers(): Promise<Player[]> {
|
||||
const res = await api.get<any[] | { data?: any[]; items?: any[] }>('/players');
|
||||
export async function getPlayers(opts?: { active?: boolean; team_id?: number | string }): Promise<Player[]> {
|
||||
let url = '/players';
|
||||
const params = new URLSearchParams();
|
||||
if (opts && opts.active === false) params.set('active', 'false');
|
||||
if (opts && opts.team_id != null) params.set('team_id', String(opts.team_id));
|
||||
if (Array.from(params.keys()).length > 0) {
|
||||
url += `?${params.toString()}`;
|
||||
}
|
||||
const res = await api.get<any[] | { data?: any[]; items?: any[] }>(url);
|
||||
const raw = Array.isArray(res.data)
|
||||
? res.data
|
||||
: ((res.data as any).data || (res.data as any).items);
|
||||
|
||||
Reference in New Issue
Block a user