REFACTOR ALL APIs fix 1

This commit is contained in:
Urtzi Alfaro
2025-10-07 07:15:07 +02:00
parent 38fb98bc27
commit 7c72f83c51
47 changed files with 1821 additions and 270 deletions

View File

@@ -17,6 +17,7 @@ import AddStockModal from '../../../../components/domain/inventory/AddStockModal
import { useIngredients, useStockAnalytics, useStockMovements, useStockByIngredient, useCreateIngredient, useSoftDeleteIngredient, useHardDeleteIngredient, useAddStock, useConsumeStock, useUpdateIngredient, useTransformationsByIngredient } from '../../../../api/hooks/inventory';
import { useTenantId } from '../../../../hooks/useTenantId';
import { IngredientResponse, StockCreate, StockMovementCreate, IngredientCreate } from '../../../../api/types/inventory';
import { subscriptionService } from '../../../../api/services/subscription';
const InventoryPage: React.FC = () => {
const [searchTerm, setSearchTerm] = useState('');
@@ -312,7 +313,21 @@ const InventoryPage: React.FC = () => {
// Handle creating a new ingredient
const handleCreateIngredient = async (ingredientData: IngredientCreate) => {
if (!tenantId) {
throw new Error('No tenant ID available');
}
try {
// Check subscription limits before creating
const usageCheck = await subscriptionService.checkUsageLimit(tenantId, 'inventory_items', 1);
if (!usageCheck.allowed) {
throw new Error(
usageCheck.message ||
`Has alcanzado el límite de ${usageCheck.limit} ingredientes para tu plan. Actualiza tu suscripción para agregar más.`
);
}
await createIngredientMutation.mutateAsync({
tenantId,
ingredientData