u
This commit is contained in:
61
src/automats/articleDetailAutomat.js
Normal file
61
src/automats/articleDetailAutomat.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import { KeyedAutomat } from 'react-automat';
|
||||
import { article as articleApi } from '../api';
|
||||
import { requireArray, requireObject } from '../utils/apiShape';
|
||||
|
||||
/**
|
||||
* @typedef {Object} ArticleHistoryEntry
|
||||
* @property {string|number} id History entry id.
|
||||
* @property {string} date Timestamp (ISO).
|
||||
* @property {string} text Human-readable change description.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ArticleSupplierRow
|
||||
* @property {string|number} id Supplier link id.
|
||||
* @property {string|number} entityId Supplier id.
|
||||
* @property {string|null} sku Supplier SKU.
|
||||
* @property {string|null} name Supplier name.
|
||||
* @property {number|null} pu Pack unit.
|
||||
* @property {number|null} stock Supplier stock.
|
||||
* @property {number|null} netPrice Net purchase price.
|
||||
* @property {number|null} taxRate Tax rate in percent.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Per-SKU article change history (`GET /api/article/{sku}/history`).
|
||||
*
|
||||
* The backend returns the full list; pagination happens client-side in
|
||||
* `ArticleHistoryTab`. Keyed by SKU so several tabs can watch the same article.
|
||||
*
|
||||
* @type {KeyedAutomat<Array<ArticleHistoryEntry>>}
|
||||
*/
|
||||
export const articleHistoryAutomat = new KeyedAutomat(
|
||||
null,
|
||||
{},
|
||||
{
|
||||
name: 'articleHistory',
|
||||
loader: async (sku) => {
|
||||
const res = await articleApi.getBySkuHistory(String(sku));
|
||||
requireObject(res, 'GET /api/article/:sku/history');
|
||||
return requireArray(res.history, 'history');
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Suppliers assigned to an article (`GET /api/article/{sku}/supplier`).
|
||||
*
|
||||
* @type {KeyedAutomat<Array<ArticleSupplierRow>>}
|
||||
*/
|
||||
export const articleSupplierAutomat = new KeyedAutomat(
|
||||
null,
|
||||
{},
|
||||
{
|
||||
name: 'articleSuppliers',
|
||||
loader: async (sku) => {
|
||||
const res = await articleApi.getSuppliers(String(sku));
|
||||
requireObject(res, 'GET /api/article/:sku/supplier');
|
||||
return requireArray(res.suppliers, 'suppliers');
|
||||
},
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user