addStock
addStock increases the quantity of a product in a single store and writes a matching entry into the stockMovement ledger. It works on the inventory model (one record per store + product) and the stockMovement model (the audit trail). You need it any time goods physically arrive at a store โ a goods receipt, a purchase order being finalized, or a manual stocking.
removeStock
removeStock decreases the quantity of a product in a store and writes a matching stockMovement entry with a negative quantity. It works on the inventory model (the quantity record) and the stockMovement model (the ledger). You need it any time goods leave a store โ a goods issue, a stock-out, or a manual write-off. Unlike addStock, it will refuse to go below zero or act on a store/product combo that has no inventory record yet.
transferStock
transferStock moves a quantity of one product from one store to another. It works on the inventory and stockMovement models. You need it when goods physically move between warehouses or shelves: the act removes stock from the source store and adds it to the destination store in a single atomic-ish unit, writing two ledger entries (transferout and transferin) so the movement is fully auditable.
getStockLevel
getStockLevel returns the current inventory document for one store + product combination โ quantity, min/max thresholds, batch info, location, and the embedded store / product relations. It works on the inventory model. You need it to answer "how much of X do we have in store Y right now?" and, thanks to the minQuantity / maxQuantity fields, to drive low-stock / over-stock alerts.
getInventories
getInventories lists inventory rows โ optionally filtered to one store and/or one product โ sorted by quantity descending. It works on the inventory model. You need it to answer "show me all stock, or everything for a store, or every store carrying this product," typically as the inventory dashboard list.
getStockMovements
getStockMovements lists the stock-movement ledger โ every addStock / removeStock / transferStock write โ optionally filtered by store, product, and reason, sorted by createdAt descending (newest first). It works on the stockMovement model. You need it to audit why inventory changed: who moved what, when, from what balance to what balance.
inventoryManager
inventoryManager.ts is the shared brain behind the inventory acts. Instead of each act inlining its own findOne / $inc / insertOne logic, the mutating acts (addStock, removeStock, transferStock) delegate here, and the read helpers getStockLevel / getProductStockLevels are used by the read acts. You need it to understand the single source of truth for stock: every write updates exactly one inventory document and appends one stockMovement ledger row, so quantity changes are always auditable.