Wire Newbook credentials to settings service

This commit is contained in:
jtricerolph 2026-07-01 19:33:16 +00:00
commit 63a5a72fa3
32 changed files with 3386 additions and 0 deletions

37
frontend/src/api.ts Normal file
View file

@ -0,0 +1,37 @@
const BASE = '/cashup/api'
async function req<T>(method: string, path: string, body?: unknown): Promise<T> {
const res = await fetch(BASE + path, {
method,
credentials: 'include',
headers: body ? { 'Content-Type': 'application/json' } : undefined,
body: body ? JSON.stringify(body) : undefined,
})
if (!res.ok) {
const err = await res.json().catch(() => ({ error: res.statusText }))
throw new Error((err as { error?: string }).error || res.statusText)
}
return res.json()
}
export const api = {
get: <T>(path: string) => req<T>('GET', path),
post: <T>(path: string, body: unknown) => req<T>('POST', path, body),
put: <T>(path: string, body: unknown) => req<T>('PUT', path, body),
delete: <T>(path: string) => req<T>('DELETE', path),
}
export async function uploadAttachment(cashUpId: number, file: File) {
const fd = new FormData()
fd.append('file', file)
const res = await fetch(`${BASE}/attachments/upload/${cashUpId}`, {
method: 'POST',
credentials: 'include',
body: fd,
})
if (!res.ok) {
const err = await res.json().catch(() => ({ error: res.statusText }))
throw new Error((err as { error?: string }).error || res.statusText)
}
return res.json()
}