const BASE_URL = process.env.NEXT_PUBLIC_SEWERAGE_API_URL || ''; export const postData = async (url: string, data: object): Promise => { const options: RequestInit = { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }; const res = await fetch(`${BASE_URL}/${url}`, options); const resData = await res.json(); return resData; }; export const postMutiPart = async (url: string, data: FormData): Promise => { const options: RequestInit = { method: "POST", body: data, }; const res = await fetch(`${BASE_URL}/${url}`, options); const resData = await res.json(); return resData; }; export const putData = async (url: string, data: object): Promise => { const options: RequestInit = { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }; const res = await fetch(`${BASE_URL}/${url}`, options); const resData = await res.json(); return resData; }; export const getData = async (url: string): Promise => { const res = await fetch(`${BASE_URL}/${url}`, { method: "GET", }); if (res.ok) { const data = await res.json(); return data; } throw new Error('Failed to fetch data'); }; export const deleteData = async (url: string, data?: object): Promise => { const options: RequestInit = { method: "DELETE", headers: { "Content-Type": "application/json", }, body: data ? JSON.stringify(data) : undefined, }; const res = await fetch(`${BASE_URL}/${url}`, options); const resData = await res.json(); return resData; };