Add Lieferungen section with supplier CRUD and delivery create/list.
Wire /lieferung sub-nav (list, neu, lieferanten) to supplier and delivery APIs.
This commit is contained in:
@@ -71,6 +71,30 @@ export class ApiClient {
|
||||
delete: (id) => this.#empty('DELETE', `/api/brand/${enc(id)}`),
|
||||
};
|
||||
|
||||
this.supplier = {
|
||||
/** GET /api/supplier → { suppliers: Supplier[] } */
|
||||
list: () => this.#json('GET', '/api/supplier'),
|
||||
/** POST /api/supplier → 201 { supplier } */
|
||||
create: (body) => this.#json('POST', '/api/supplier', { body }),
|
||||
/** PATCH /api/supplier/{id} → { supplier } */
|
||||
update: (id, body) => this.#json('PATCH', `/api/supplier/${enc(id)}`, { body }),
|
||||
/** DELETE /api/supplier/{id} → 204 */
|
||||
delete: (id) => this.#empty('DELETE', `/api/supplier/${enc(id)}`),
|
||||
};
|
||||
|
||||
this.delivery = {
|
||||
/** GET /api/delivery → { deliveries: DeliverySummary[] } */
|
||||
list: () => this.#json('GET', '/api/delivery'),
|
||||
/** GET /api/delivery/{id} → { delivery: Delivery } */
|
||||
get: (id) => this.#json('GET', `/api/delivery/${enc(id)}`),
|
||||
/** POST /api/delivery → 201 { delivery: Delivery } */
|
||||
create: (body) => this.#json('POST', '/api/delivery', { body }),
|
||||
/** PATCH /api/delivery/{id} → { delivery: Delivery } */
|
||||
update: (id, body) => this.#json('PATCH', `/api/delivery/${enc(id)}`, { body }),
|
||||
/** DELETE /api/delivery/{id} → 204 */
|
||||
delete: (id) => this.#empty('DELETE', `/api/delivery/${enc(id)}`),
|
||||
};
|
||||
|
||||
this.category = {
|
||||
/** GET /api/category/tree */
|
||||
tree: () => this.#json('GET', '/api/category/tree'),
|
||||
|
||||
@@ -291,6 +291,8 @@ export class StorageManager extends ApiClient {
|
||||
const companyCache = createCache('GET /company', () => this.#loadCompanies());
|
||||
const categoryTreeCache = createCache('GET /category/tree', () => this.#loadCategoryTree());
|
||||
const posterminalCache = createCache('GET /posterminal', () => this.#loadPosterminals());
|
||||
const supplierCache = createCache('GET /supplier', () => this.#loadSuppliers());
|
||||
const deliveryCache = createCache('GET /delivery', () => this.#loadDeliveries());
|
||||
|
||||
Object.defineProperties(this, {
|
||||
authMePromise: { get: () => authMeCache.promise },
|
||||
@@ -324,6 +326,16 @@ export class StorageManager extends ApiClient {
|
||||
posterminalPromise: { get: () => posterminalCache.promise },
|
||||
updatePosterminal: { value: posterminalCache.update },
|
||||
|
||||
supplierPromise: { get: () => supplierCache.promise },
|
||||
updateSupplier: { value: supplierCache.update },
|
||||
/** Settled GET /supplier list, or undefined. */
|
||||
suppliers: { get: () => supplierCache.value },
|
||||
|
||||
deliveryPromise: { get: () => deliveryCache.promise },
|
||||
updateDelivery: { value: deliveryCache.update },
|
||||
/** Settled GET /delivery list, or undefined. */
|
||||
deliveries: { get: () => deliveryCache.value },
|
||||
|
||||
/** Close and reopen GET /api/events (required after selected-company change). */
|
||||
reconnectEvents: { value: () => this.#reconnectEvents() },
|
||||
});
|
||||
@@ -444,6 +456,18 @@ export class StorageManager extends ApiClient {
|
||||
return requireArray(data.posterminals, 'posterminals');
|
||||
}
|
||||
|
||||
async #loadSuppliers() {
|
||||
const data = await this.supplier.list();
|
||||
requireObject(data, 'GET /api/supplier');
|
||||
return requireArray(data.suppliers, 'suppliers');
|
||||
}
|
||||
|
||||
async #loadDeliveries() {
|
||||
const data = await this.delivery.list();
|
||||
requireObject(data, 'GET /api/delivery');
|
||||
return requireArray(data.deliveries, 'deliveries');
|
||||
}
|
||||
|
||||
async doSearch({ target, filter, offset, maxCount, onUpdate }) {
|
||||
const articles = await this.articleIndexPromise;
|
||||
const query = target.trim().toLowerCase();
|
||||
|
||||
@@ -521,6 +521,84 @@ export const brand = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Company-scoped suppliers / Lieferanten (selectedCompanyId from session).
|
||||
* Shape: Supplier = { id, name, createdAt, updatedAt }
|
||||
*/
|
||||
export const supplier = {
|
||||
/** GET /api/supplier → { suppliers: Supplier[] } */
|
||||
list() {
|
||||
return http('/api/supplier');
|
||||
},
|
||||
|
||||
/**
|
||||
* POST /api/supplier
|
||||
* Body: { name } — empty name ⇒ 400 Name required.
|
||||
* → 201 { supplier: Supplier }
|
||||
*/
|
||||
create(body) {
|
||||
return http('/api/supplier', { method: 'POST', body });
|
||||
},
|
||||
|
||||
/**
|
||||
* PATCH /api/supplier/:id
|
||||
* Body: { name } — empty name ⇒ 400 Name required.
|
||||
* → 200 { supplier: Supplier }
|
||||
*/
|
||||
update(id, body) {
|
||||
return http(`/api/supplier/${id}`, { method: 'PATCH', body });
|
||||
},
|
||||
|
||||
/** DELETE /api/supplier/:id → 204 */
|
||||
delete(id) {
|
||||
return http(`/api/supplier/${id}`, { method: 'DELETE' });
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Company-scoped goods receipts (manifest type = delivery).
|
||||
* DeliverySummary = { id, number, type: 'delivery', supplierId, date }
|
||||
* DeliveryLine = { id, articleId, sku, amount, net, transactedAmount, rebate, tax, comment }
|
||||
* Delivery = DeliverySummary & { lines: DeliveryLine[] }
|
||||
* DeliveryLineInput = { sku, amount, net, tax, rebate?, transactedAmount?, comment? }
|
||||
*/
|
||||
export const delivery = {
|
||||
/** GET /api/delivery → { deliveries: DeliverySummary[] } */
|
||||
list() {
|
||||
return http('/api/delivery');
|
||||
},
|
||||
|
||||
/** GET /api/delivery/:id → { delivery: Delivery } */
|
||||
get(id) {
|
||||
return http(`/api/delivery/${id}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* POST /api/delivery
|
||||
* Body: { number, date, supplierId?, lines: DeliveryLineInput[] }
|
||||
* Line requires sku, amount, net, tax. rebate→0, transactedAmount→amount.
|
||||
* → 201 { delivery: Delivery }
|
||||
*/
|
||||
create(body) {
|
||||
return http('/api/delivery', { method: 'POST', body });
|
||||
},
|
||||
|
||||
/**
|
||||
* PATCH /api/delivery/:id
|
||||
* Body: partial { number?, date?, supplierId?, lines? }.
|
||||
* If lines present, replaces all lines; if omitted, lines unchanged.
|
||||
* → 200 { delivery: Delivery }
|
||||
*/
|
||||
update(id, body) {
|
||||
return http(`/api/delivery/${id}`, { method: 'PATCH', body });
|
||||
},
|
||||
|
||||
/** DELETE /api/delivery/:id → 204 */
|
||||
delete(id) {
|
||||
return http(`/api/delivery/${id}`, { method: 'DELETE' });
|
||||
},
|
||||
};
|
||||
|
||||
export const company = {
|
||||
/** GET /api/company → { companies: [...] } */
|
||||
list() {
|
||||
@@ -697,6 +775,8 @@ export default {
|
||||
category,
|
||||
company,
|
||||
posterminal,
|
||||
supplier,
|
||||
delivery,
|
||||
thumb,
|
||||
unit,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user