update api fetch client

This commit is contained in:
Fran Jurmanović
2025-09-14 19:04:24 +02:00
parent 8a5afee0e3
commit 373adcb49d
6 changed files with 73 additions and 37 deletions

View File

@@ -1,30 +1,31 @@
import { fetchServerAPI } from './base';
import { Server } from '@/lib/types/server';
import { Server, ServiceStatus } from '@/lib/types/server';
const serverRoute = '/server';
export async function getServers(token: string): Promise<Server[]> {
const response = await fetchServerAPI<Server[]>(serverRoute, token);
return response;
return response.data!;
}
export async function getServer(token: string, serverId: string): Promise<Server> {
const response = await fetchServerAPI<Server>(`${serverRoute}/${serverId}`, token);
return response;
return response.data!;
}
export async function restartService(token: string, serverId: string) {
return fetchServerAPI(`${serverRoute}/${serverId}/service/restart`, token, 'POST');
export async function restartService(token: string, serverId: string): Promise<void> {
await fetchServerAPI(`${serverRoute}/${serverId}/service/restart`, token, 'POST');
}
export async function startService(token: string, serverId: string) {
return fetchServerAPI(`${serverRoute}/${serverId}/service/start`, token, 'POST');
export async function startService(token: string, serverId: string): Promise<void> {
await fetchServerAPI(`${serverRoute}/${serverId}/service/start`, token, 'POST');
}
export async function stopService(token: string, serverId: string) {
return fetchServerAPI(`${serverRoute}/${serverId}/service/stop`, token, 'POST');
export async function stopService(token: string, serverId: string): Promise<void> {
await fetchServerAPI(`${serverRoute}/${serverId}/service/stop`, token, 'POST');
}
export async function getServiceStatus(token: string, serverId: string) {
return fetchServerAPI(`${serverRoute}/${serverId}/service`, token);
export async function getServiceStatus(token: string, serverId: string): Promise<ServiceStatus> {
const response = await fetchServerAPI<ServiceStatus>(`${serverRoute}/${serverId}/service`, token);
return response.data!;
}