Initialize work order management system with database schema, API handlers, web client, and Docker configuration.

This commit is contained in:
2026-05-16 16:15:53 -04:00
parent c135722339
commit f904431ec3
28 changed files with 2171 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
const BASE = '/api';
let _token = '';
export function setToken(t) { _token = t; }
export function getToken() { return _token; }
async function request(method, path, body, isForm = false) {
const headers = { Authorization: `Bearer ${_token}` };
if (!isForm && body) headers['Content-Type'] = 'application/json';
const res = await fetch(BASE + path, {
method,
headers,
body: body ? (isForm ? body : JSON.stringify(body)) : undefined,
});
if (res.status === 401) {
window.dispatchEvent(new CustomEvent('auth:expired'));
return null;
}
const json = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(json.error || `HTTP ${res.status}`);
return json.data;
}
export const api = {
get: (path) => request('GET', path),
post: (path, body) => request('POST', path, body),
put: (path, body) => request('PUT', path, body),
delete: (path) => request('DELETE', path),
upload: (path, form) => request('POST', path, form, true),
};