Files
2026-04-11 12:12:07 +02:00

2 lines
3.0 KiB
JavaScript

import{w as o}from"./oVx0hpG8.js";import{h as p}from"./DHedsUi_.js";const d=o(null),u=o(null),n="/api";async function a(e,t,r,c=!1){const i=p(u),l={};i&&(l.Authorization=i),r&&!c&&(l["Content-Type"]="application/json");const s=await fetch(`${n}${t}`,{method:e,headers:l,body:c?r:r?JSON.stringify(r):void 0,credentials:"include"});if(s.status===401){d.set(null),u.set(null),window.location.href="/login";return}if(!s.ok){const E=await s.text();throw new Error(E||`HTTP ${s.status}`)}return s.status===204?null:s.json()}const m={auth:{login:(e,t)=>a("POST","/auth/login",{email:e,password:t}),logout:()=>a("POST","/auth/logout"),register:e=>a("POST","/auth/register",e),me:()=>a("GET","/me"),updateProfile:e=>a("PUT","/me",e),updatePassword:e=>a("PUT","/me/password",e)},users:{list:()=>a("GET","/users"),delete:e=>a("DELETE",`/users/${e}`)},categories:{list:(e={})=>a("GET",`/categories?${new URLSearchParams(e)}`),create:e=>a("POST","/categories",e),update:(e,t)=>a("PUT",`/categories/${e}`,t),delete:e=>a("DELETE",`/categories/${e}`)},properties:{list:()=>a("GET","/properties"),get:e=>a("GET",`/properties/${e}`),create:e=>a("POST","/properties",e),update:(e,t)=>a("PUT",`/properties/${e}`,t),delete:e=>a("DELETE",`/properties/${e}`)},transactions:{list:(e={})=>a("GET",`/transactions?${new URLSearchParams(e)}`),create:e=>a("POST","/transactions",e),update:(e,t)=>a("PUT",`/transactions/${e}`,t),delete:e=>a("DELETE",`/transactions/${e}`),split:(e,t)=>a("POST",`/transactions/${e}/split`,t),summary:(e={})=>a("GET",`/transactions/summary?${new URLSearchParams(e)}`),monthly:(e={})=>a("GET",`/transactions/monthly?${new URLSearchParams(e)}`),categories:(e={})=>a("GET",`/transactions/categories?${new URLSearchParams(e)}`)},calendar:{list:(e={})=>a("GET",`/calendar?${new URLSearchParams(e)}`),createEvent:e=>a("POST","/calendar",e),updateEvent:(e,t)=>a("PUT",`/calendar/${e}`,t),deleteEvent:e=>a("DELETE",`/calendar/${e}`),stats:(e={})=>a("GET",`/calendar/stats?${new URLSearchParams(e)}`),sync:e=>a("POST",`/calendar/sync/${e}`)},documents:{list:(e={})=>a("GET",`/documents?${new URLSearchParams(e)}`),upload:e=>a("POST","/documents",e,!0),download:e=>`${n}/documents/${e}/download`,delete:e=>a("DELETE",`/documents/${e}`),exportUrl:(e={})=>`${n}/documents/export?${new URLSearchParams(e)}`},loans:{list:(e={})=>a("GET",`/loans?${new URLSearchParams(e)}`),createWithData:e=>a("POST","/loans/create",e),create:e=>a("POST","/loans",e),delete:e=>a("DELETE",`/loans/${e}`),lines:(e,t={})=>a("GET",`/loans/${e}/lines?${new URLSearchParams(t)}`),annualSummary:(e,t={})=>a("GET",`/loans/${e}/summary?${new URLSearchParams(t)}`),uploadLines:(e,t)=>a("POST",`/loans/${e}/lines`,t),splitByDate:(e,t)=>a("GET",`/loans/${e}/split?date=${t}`),splitForDate:e=>a("GET",`/loans/split?date=${e}`)},fiscal:{summary:(e={})=>a("GET",`/fiscal/summary?${new URLSearchParams(e)}`),exportUrl:(e={})=>`${n}/fiscal/export?${new URLSearchParams(e)}`}},$=o([]),T=o(null);async function h(){const e=await m.properties.list();$.set(e||[]),!p(T)&&(e==null?void 0:e.length)>0&&T.set(e[0])}export{m as a,u as b,d as c,h as l,$ as p};