import { Game } from "@/types/stellaris" type Parameter = { key: string, val: string | number } const baseUrl = 'http://stellaris.neshweb.net/api/v2' export const generateUrl = (url: string, params?: Parameter[]) => { let query: string = baseUrl + url; if (params && params.length > 0) { query = query + '?'; params.forEach((param, idx) => { query = query + param.key + '=' + param.val; if (idx + 1 != params.length) { query = query + '&'; } }); } return query; } export const fetchGameGroups = async (game: Game) => { const gameGroups = await fetch(generateUrl('/game_groups', [{key: "game_id", val: game.id}])).then((res) => res.json()) return gameGroups }