Credith manages product stock at the per-store level. Rather than tracking a single global quantity for each product, Credith uses a junction table —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/RoyGeova07/Credith/llms.txt
Use this file to discover all available pages before exploring further.
stores_inventories — that links every (store, product) pair to an independent in_stock count. This means the same product can have 20 units at one branch and 3 at another, and each store’s inventory is managed and reported independently. Stock levels are decremented automatically during bill creation and can be adjusted, transferred, or queried through the inventory API.
The stores_inventories Table
The stores_inventories table acts as a many-to-many join between stores and products, with additional columns for tracking current stock.
| Field | Type | Description |
|---|---|---|
product_id | UUID | FK → products.product_id. Part of the composite primary key. |
store_id | UUID | FK → stores.store_id. Part of the composite primary key. |
in_stock | INTEGER | Current number of units available at this store. Defaults to 1. |
is_active | BOOLEAN | Whether this inventory entry is active. Defaults to true. |
stores_inventories uses a composite primary key (product_id + store_id) and has no created_at/updated_at timestamps, unlike most other tables in the cd schema.
Automatic Stock Decrement During Bill Creation
When a new bill is posted viaPOST /api/bills, stock is decremented for every line item inside the same database transaction that creates the bill, bill details, CAI number, and payment plan. This ensures atomicity — if any part of the bill fails, inventory is not touched.
The is_active Flag
Each inventory entry carries an is_active boolean flag. This allows store operators to deactivate a product at a specific store without deleting the record or affecting stock at other stores. An inactive inventory entry signals that the product is not currently being sold at that location, even if in_stock > 0.
Products Across Multiple Stores
Becausestores_inventories is a many-to-many join table, a single product can be stocked at many stores simultaneously, each with its own independent in_stock count:
store_id.
API Reference
All inventory endpoints are mounted under the/api/store-inventory prefix and require authentication via the authMiddleware cookie token.
GET /api/store-inventory/store/:storeId — Full store inventory
GET /api/store-inventory/store/:storeId — Full store inventory
in_stock count from the stores_inventories through-table. Requires OWNER role.Store record with an embedded products array, each product carrying { inStock } from the junction.GET /api/store-inventory/my-store — Current user's store inventory
GET /api/store-inventory/my-store — Current user's store inventory
req.user.storeId). Includes productId, name, description, sellPrice, buyPrice, imageUrl, and minGainPercentage per product. Available to all authenticated roles.{ total, data[] } where each item includes the product details and inStock.GET /api/store-inventory — Paginated inventory across all stores
GET /api/store-inventory — Paginated inventory across all stores
stores_inventories records with pagination, including product name/price and store information. Requires OWNER role.{ total, data[] }.GET /api/store-inventory/:storeId/:productId — Single product stock
GET /api/store-inventory/:storeId/:productId — Single product stock
stores_inventories record for a specific product at a specific store. Requires OWNER role.inStock and isActive.PATCH /api/store-inventory/stock — Update stock level
PATCH /api/store-inventory/stock — Update stock level
in_stock count for a (product, store) pair. Useful for corrections after physical stock counts. Requires OWNER or ADMIN role.stock must be ≥ 0. Returns { message, stockActual }.POST /api/store-inventory/transfer — Transfer stock between stores
POST /api/store-inventory/transfer — Transfer stock between stores
OWNER role.fromStoreIdandtoStoreIdmust be different.- Source store must have at least
quantityunits in stock. quantitymust be≥ 1.
GET /api/store-inventory/low-stock — Items below threshold
GET /api/store-inventory/low-stock — Items below threshold
in_stock is at or below a configurable threshold. Useful for reorder alerts. Requires OWNER or ADMIN role.- OWNER role: returns low-stock items across all stores belonging to their company.
- ADMIN role: returns low-stock items only for their assigned store.
threshold is 5 if not specified.Relationship to Reporting
The inventory system feeds directly into the product performance report atGET /api/reports/products. That endpoint joins stores_inventories.in_stock with bill detail quantities to return side-by-side in-stock vs. sold counts per product per store — giving owners a live picture of which products are moving and which are stagnating on shelves.