18 lines
1.5 KiB
JavaScript
18 lines
1.5 KiB
JavaScript
/** Stock mutations are superuser-only commands, never unaudited record patches. */
|
|
routerAdd("GET", "/api/wfdash/stock-movements-capability", (e) => {
|
|
const movements = require(`${__hooks}/stock_movement_utils.js`);
|
|
movements.assertSchema(e.app);
|
|
return e.json(200, { version: 1 });
|
|
}, $apis.requireSuperuserAuth());
|
|
routerAdd("POST", "/api/wfdash/stock-movements", (e) => {
|
|
const movements = require(`${__hooks}/stock_movement_utils.js`);
|
|
return e.json(200, movements.command(e, e.requestInfo().body));
|
|
}, $apis.requireSuperuserAuth());
|
|
onRecordUpdateRequest((e) => require(`${__hooks}/stock_movement_utils.js`).protectUpdate(e), "stock_items");
|
|
onRecordCreateRequest((e) => require(`${__hooks}/stock_movement_utils.js`).protectCreate(e), "stock_items");
|
|
onRecordCreateRequest((e) => require(`${__hooks}/stock_movement_utils.js`).protectLedger(e), "stock_ledger");
|
|
onRecordUpdateRequest((e) => require(`${__hooks}/stock_movement_utils.js`).protectLedgerUpdate(e), "stock_ledger");
|
|
onRecordDeleteRequest((e) => { throw new ForbiddenError("Stock movement history cannot be deleted."); }, "stock_ledger");
|
|
onRecordCreateRequest((e) => { throw new ForbiddenError("Use the transactional stock movement command."); }, "stock_movement_operations");
|
|
onRecordUpdateRequest((e) => { throw new ForbiddenError("Stock movement operations are immutable."); }, "stock_movement_operations");
|
|
onRecordDeleteRequest((e) => { throw new ForbiddenError("Stock movement operations cannot be deleted."); }, "stock_movement_operations");
|