ui: Refactor service api functions

This commit is contained in:
nemunaire 2024-01-19 16:22:25 +01:00
parent 4b5d014500
commit 2420c9c1b4
1 changed files with 3 additions and 13 deletions

View File

@ -22,19 +22,9 @@
import { handleEmptyApiResponse, handleApiResponse } from '$lib/errors';
import type { ServiceCombined } from '$lib/model/service';
export async function updateService(zoneid: string, svc: ServiceCombined): Promise<ServiceCombined> {
const res = await fetch('/api/zone/' + zoneid + '/services/' + (svc._id ? `/${svc._id}` : ''), {
method: svc._id?'PUT':'POST',
headers: {'Accept': 'application/json'},
body: JSON.stringify(svc),
export async function getService(domain: Domain | DomainInList, zoneid: string, subdomain: string, svcid: string): Promise<ServiceCombined> {
const res = await fetch(`/api/domains/${encodeURIComponent(domain.id)}/zone/${encodeURIComponent(zoneid)}/${encodeURIComponent(subdomain)}/services/${encodeURIComponent(svcid)}`, {
headers: {'Accept': 'application/json'}
});
return await handleApiResponse<ServiceCombined>(res);
}
export async function deleteService(zoneid: string, id: string): Promise<boolean> {
const res = await fetch(`/api/zone/${zoneid}/services/${id}`, {
method: 'DELETE',
headers: {'Accept': 'application/json'},
});
return await handleEmptyApiResponse(res);
}