This commit is contained in:
seb
2026-09-26 23:05:48 +02:00
parent 454c5ab6bf
commit 3ab9d904e6
12 changed files with 1505 additions and 65 deletions

View File

@@ -94,6 +94,24 @@ export class ApiClient {
},
};
this.warehouse = {
/** GET /api/warehouse → { warehouses: Warehouse[] } */
list: () => this.#json('GET', '/api/warehouse'),
/** GET /api/warehouse/{id} → { warehouse: Warehouse } */
getById: (id) => this.#json('GET', `/api/warehouse/${enc(id)}`),
/** POST /api/warehouse → 201 { warehouse: Warehouse } */
create: (body) => this.#json('POST', '/api/warehouse', { body }),
/** PATCH /api/warehouse/{id} → 200 { warehouse: Warehouse } */
update: (id, body) => this.#json('PATCH', `/api/warehouse/${enc(id)}`, { body }),
/** DELETE /api/warehouse/{id} → 204 */
delete: (id) => this.#empty('DELETE', `/api/warehouse/${enc(id)}`),
};
this.stock = {
/** POST /api/stock/adjust → 201 { manifest, lines, ledger } */
adjust: (body) => this.#json('POST', '/api/stock/adjust', { body }),
};
this.delivery = {
/** GET /api/delivery → { deliveries: DeliverySummary[] } */
list: () => this.#json('GET', '/api/delivery'),

View File

@@ -8,6 +8,7 @@ import unitAutomat from '../automats/unitAutomat';
import authAutomat from '../automats/authAutomat';
import categoryAutomat, { invalidateAllCategoryViews } from '../automats/categoryAutomat';
import posterminalAutomat from '../automats/posterminalAutomat';
import warehouseAutomat from '../automats/warehouseAutomat';
/**
@@ -677,6 +678,11 @@ export class StorageManager extends ApiClient {
console.error('[storageMgr] articles SSE refresh failed', err);
});
});
es.addEventListener('warehouse', () => {
void warehouseAutomat.actions.reload().catch((err) => {
console.error('[storageMgr] warehouse SSE refresh failed', err);
});
});
for (const sku of new Set([
...this.#articleWatchers.keys(),
...this.#historyWatchers.keys(),

View File

@@ -633,6 +633,58 @@ export const supplier = {
},
};
/**
* Company-scoped warehouses / Lager (selectedCompanyId from session).
* Shape: Warehouse = { id, name }
*/
export const warehouse = {
/** GET /api/warehouse → { warehouses: Warehouse[] } */
list() {
return http('/api/warehouse');
},
/** GET /api/warehouse/:id → { warehouse: Warehouse } */
getById(id) {
return http(`/api/warehouse/${id}`);
},
/**
* POST /api/warehouse
* Body: { name } — empty name ⇒ 400 Name required.
* → 201 { warehouse: Warehouse }
*/
create(body) {
return http('/api/warehouse', { method: 'POST', body });
},
/**
* PATCH /api/warehouse/:id
* Body: { name } — empty name ⇒ 400 Name required.
* → 200 { warehouse: Warehouse }
*/
update(id, body) {
return http(`/api/warehouse/${id}`, { method: 'PATCH', body });
},
/** DELETE /api/warehouse/:id → 204 */
delete(id) {
return http(`/api/warehouse/${id}`, { method: 'DELETE' });
},
};
/**
* Stock operations (manual stock adjustment).
*/
export const stock = {
/**
* POST /api/stock/adjust
* Body: { sku, warehouseId, amount, text?, date?, externalNumber?, lines? }
*/
adjust(body) {
return http('/api/stock/adjust', { method: 'POST', body });
},
};
/**
* Company-scoped goods receipts (manifest type = delivery).
* DeliverySummary = { id, number, externalNumber, type: 'delivery', supplierId, date }
@@ -1264,4 +1316,6 @@ export default {
supplier,
thumb,
unit,
warehouse,
stock,
};