Overview
Inventory operations provide hooks and API functions for querying, searching, and updating inventory items. All operations are location-scoped based on the user’s current location.
useInventory
Paginated inventory query with filtering and sorting.
import { useInventory } from '@/entities/inventario';
const { data, isLoading, error } = useInventory({
page: 1,
limit: 10,
search: 'alternador',
order_by: 'referencia',
direction: 'asc'
});
Parameters
Page number for pagination
order_by
string
default:"referencia"
Field to sort by (referencia, nombre, stock_actual)
direction
'asc' | 'desc'
default:"asc"
Sort direction
Search query for nombre or referencia
Filter by stock status (bajo_minimo, normal, sin_stock)
Filter by discontinued status
Show only items marked as new
Response
Total number of items matching filters
useSearchInventory
Autocomplete search for inventory items.
import { useSearchInventory } from '@/entities/inventario';
const { data: items, isLoading } = useSearchInventory('alternador', true);
Parameters
Whether to enable the query
Response
Returns InventoryItem[] matching the search query (max 50 results).
API Functions
getInventory
Direct API call for fetching paginated inventory.
import { getInventory } from '@/entities/inventario/api';
const response = await getInventory({
page: 1,
limit: 20,
search: 'filtro',
estado_stock: 'bajo_minimo'
});
searchInventoryItems
Search inventory items by query.
import { searchInventoryItems } from '@/entities/inventario/api';
const items = await searchInventoryItems('alternador');
getAllInventoryItems
Fetch all inventory items for current location.
import { getAllInventoryItems } from '@/entities/inventario/api';
const allItems = await getAllInventoryItems();
// Returns up to 1000 items
updateItemComplete
Update inventory item using RPC function.
import { updateItemComplete } from '@/entities/inventario/api';
await updateItemComplete(
'uuid-inventory-id',
25, // stock_actual
'A1-B2', // posicion
10, // cantidad_minima
false, // descontinuado
'repuesto', // tipo
'2024-12-31',// fecha_estimada
'2024-06-30' // nuevo_hasta
);
Parameters
Warehouse position/location
Whether item is discontinued
Estimated restock date (ISO format)
Date until item is marked as “new” (ISO format)
Types
InventoryItem
interface InventoryItem {
// Inventory fields
id_inventario: string;
id_localizacion: string;
stock_actual: number;
posicion: string;
// Spare part fields
id_repuesto: string;
referencia: string;
nombre: string;
cantidad_minima: number;
descontinuado: boolean;
tipo: string;
fecha_estimada: string;
url_imagen: string;
estado_stock: string;
fecha_ingreso_inventario: string;
nuevo_hasta: string | null;
}
InventoryParams
interface InventoryParams {
page?: number;
limit?: number;
order_by?: string;
direction?: 'asc' | 'desc';
search?: string;
estado_stock?: string;
descontinuado?: boolean;
is_new?: boolean;
}
PaginatedInventoryResponse
interface PaginatedInventoryResponse {
items: InventoryItem[];
total_count: number;
page: number;
limit: number;
page_count: number;
}
Example Usage
import { useInventory, useSearchInventory } from '@/entities/inventario';
import { useState } from 'react';
function InventoryList() {
const [page, setPage] = useState(1);
const [search, setSearch] = useState('');
const { data, isLoading } = useInventory({
page,
limit: 20,
search,
order_by: 'nombre',
direction: 'asc',
estado_stock: 'bajo_minimo'
});
if (isLoading) return <div>Loading...</div>;
return (
<div>
<input
type="text"
value={search}
onChange={(e) => setSearch(e.target.value)}
placeholder="Search inventory..."
/>
{data?.items.map(item => (
<div key={item.id_inventario}>
<h3>{item.nombre}</h3>
<p>Stock: {item.stock_actual}</p>
<p>Position: {item.posicion}</p>
</div>
))}
<Pagination
currentPage={page}
totalPages={data?.page_count || 0}
onPageChange={setPage}
/>
</div>
);
}