- Fix history nav: type underscore → hyphen for route match - Change tin: Bags + Loose inputs per denomination with UK bag values - Change tin target: per-denomination bag count in Settings - Change order sheet: inline table showing bags to order vs counted - db: bag_quantity column on float_denominations - api.ts: put text fields before file in FormData so busboy doesn't drain file stream early - db.js: additive migration for uploaded_by column on cash_count_attachments Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
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,
|
|
attachmentType: 'pdq_z_report' | 'receipt_error' | 'other' = 'other',
|
|
label?: string,
|
|
) {
|
|
const fd = new FormData()
|
|
fd.append('attachment_type', attachmentType)
|
|
if (label) fd.append('label', label)
|
|
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()
|
|
}
|