Initial electronics inventory webapp
KV-store backed Express 5 app for tracking electronic components, their arbitrary fields, and inventory locations (physical, BOM, digital). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
29
public/lib/api.mjs
Normal file
29
public/lib/api.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
async function req(method, path, body) {
|
||||
const opts = { method, headers: {} };
|
||||
if (body !== undefined) {
|
||||
opts.headers['Content-Type'] = 'application/json';
|
||||
opts.body = JSON.stringify(body);
|
||||
}
|
||||
const res = await fetch(path, opts);
|
||||
const data = await res.json();
|
||||
if (!data.ok) throw new Error(data.error ?? 'Request failed');
|
||||
return data;
|
||||
}
|
||||
|
||||
// Fields
|
||||
export const get_fields = () => req('GET', '/api/fields');
|
||||
export const create_field = (body) => req('POST', '/api/fields', body);
|
||||
export const update_field = (id, body) => req('PUT', `/api/fields/${id}`, body);
|
||||
export const delete_field = (id) => req('DELETE', `/api/fields/${id}`);
|
||||
|
||||
// Components
|
||||
export const get_components = () => req('GET', '/api/components');
|
||||
export const create_component = (body) => req('POST', '/api/components', body);
|
||||
export const update_component = (id, body) => req('PUT', `/api/components/${id}`, body);
|
||||
export const delete_component = (id) => req('DELETE', `/api/components/${id}`);
|
||||
|
||||
// Inventory
|
||||
export const get_inventory = () => req('GET', '/api/inventory');
|
||||
export const create_inventory = (body) => req('POST', '/api/inventory', body);
|
||||
export const update_inventory = (id, body) => req('PUT', `/api/inventory/${id}`, body);
|
||||
export const delete_inventory = (id) => req('DELETE', `/api/inventory/${id}`);
|
||||
Reference in New Issue
Block a user