frontend/requests/services.ts
2025-06-05 21:51:14 +02:00

27 lines
674 B
TypeScript

import axios, { type AxiosRequestConfig } from "axios";
import type { Service } from "~/classes/Service";
export function getServices(namespace: string | undefined, onSuccess: (services: Service[]) => void)
{
axios.get<Service[]>(useRuntimeConfig().public.apiBase + '/services', {
headers: {
Authorization: "Bearer " + requireToken()
},
params: getParams(namespace)
})
.then(response => {
onSuccess(response.data);
})
.catch();
}
function getParams(namespace: string | undefined)
{
if(namespace != undefined)
{
return {
namespace: namespace
}
}
return undefined;
}