Skip to main content

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
default:"1"
Page number for pagination
limit
number
default:"10"
Items per page
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
estado_stock
string
Filter by stock status (bajo_minimo, normal, sin_stock)
descontinuado
boolean
Filter by discontinued status
is_new
boolean
Show only items marked as new

Response

items
InventoryItem[]
Array of inventory items
total_count
number
Total number of items matching filters
page
number
Current page number
limit
number
Items per page
page_count
number
Total number of pages

useSearchInventory

Autocomplete search for inventory items.
import { useSearchInventory } from '@/entities/inventario';

const { data: items, isLoading } = useSearchInventory('alternador', true);

Parameters

query
string
required
Search query string
enabled
boolean
default:"true"
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

id_inventario
string
required
Inventory item UUID
stock_actual
number
required
Current stock quantity
posicion
string
required
Warehouse position/location
cantidad_minima
number
required
Minimum stock threshold
descontinuado
boolean
required
Whether item is discontinued
tipo
string
required
Item type
fecha_estimada
string | null
required
Estimated restock date (ISO format)
nuevo_hasta
string | null
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>
  );
}

Build docs developers (and LLMs) love