Code maintainability fixes

This commit is contained in:
AG
2025-12-06 11:32:40 +02:00
parent a13ef9f479
commit 4106f3b783
23 changed files with 1775 additions and 796 deletions

View File

@@ -13,12 +13,12 @@ const headers = () => {
};
export const api = {
get: async (endpoint: string) => {
get: async <T = any>(endpoint: string): Promise<T> => {
const res = await fetch(`${API_URL}${endpoint}`, { headers: headers() });
if (!res.ok) throw new Error(await res.text());
return res.json();
},
post: async (endpoint: string, data: any) => {
post: async <T = any>(endpoint: string, data: any): Promise<T> => {
const res = await fetch(`${API_URL}${endpoint}`, {
method: 'POST',
headers: headers(),
@@ -27,7 +27,7 @@ export const api = {
if (!res.ok) throw new Error(await res.text());
return res.json();
},
put: async (endpoint: string, data: any) => {
put: async <T = any>(endpoint: string, data: any): Promise<T> => {
const res = await fetch(`${API_URL}${endpoint}`, {
method: 'PUT',
headers: headers(),
@@ -36,7 +36,7 @@ export const api = {
if (!res.ok) throw new Error(await res.text());
return res.json();
},
delete: async (endpoint: string) => {
delete: async <T = any>(endpoint: string): Promise<T> => {
const res = await fetch(`${API_URL}${endpoint}`, {
method: 'DELETE',
headers: headers()
@@ -44,7 +44,7 @@ export const api = {
if (!res.ok) throw new Error(await res.text());
return res.json();
},
patch: async (endpoint: string, data: any) => {
patch: async <T = any>(endpoint: string, data: any): Promise<T> => {
const res = await fetch(`${API_URL}${endpoint}`, {
method: 'PATCH',
headers: headers(),