Fix suppliers

This commit is contained in:
Urtzi Alfaro
2025-12-29 14:48:24 +01:00
parent 2e7e1f5557
commit adef7971a0
3 changed files with 10 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ Supplier Business Operations API endpoints (BUSINESS)
Handles approvals, status updates, active/top suppliers, and delivery/PO operations
"""
from fastapi import APIRouter, Depends, HTTPException, Query, Path, Header
from fastapi import APIRouter, Depends, HTTPException, Query, Path
from typing import List, Optional, Dict, Any
from uuid import UUID
from datetime import datetime
@@ -172,20 +172,16 @@ async def get_suppliers_by_type(
@router.get(route_builder.build_operations_route("count"))
async def get_supplier_count(
tenant_id: str = Path(..., description="Tenant ID"),
x_internal_request: str = Header(None),
current_user: Dict[str, Any] = Depends(get_current_user_dep),
db: Session = Depends(get_db)
):
"""
Get total count of suppliers for a tenant
Internal endpoint for subscription usage tracking
Used for subscription usage tracking and dashboard metrics
"""
if x_internal_request != "true":
raise HTTPException(status_code=403, detail="Internal endpoint only")
try:
service = SupplierService(db)
suppliers = await service.get_suppliers(tenant_id=current_user["tenant_id"])
suppliers = await service.get_active_suppliers(tenant_id=UUID(current_user["tenant_id"]))
count = len(suppliers)
return {"count": count}

View File

@@ -280,7 +280,7 @@ class SupplierService:
async def get_active_suppliers(self, tenant_id: UUID) -> List[Supplier]:
"""Get all active suppliers"""
return self.repository.get_active_suppliers(tenant_id)
return await self.repository.get_active_suppliers(tenant_id)
async def get_suppliers_by_type(
self,