feat: filter equipment import by tenant-company mapping
All checks were successful
Deploy to Production / deploy (push) Successful in 2m7s
All checks were successful
Deploy to Production / deploy (push) Successful in 2m7s
- Add digital_twin_company_id column to tenants table - Map spifox tenant to its digital-twin companyId - Pass companyId filter when fetching from digital-twin API - Return 404 with clear message for unmapped tenants - Improve API error messages in frontend (show server detail)
This commit is contained in:
@@ -9,7 +9,7 @@ from pydantic import BaseModel
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from src.database.models import Machine, MachineChangeHistory
|
||||
from src.database.models import Machine, MachineChangeHistory, Tenant
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -101,10 +101,23 @@ class EquipmentSyncService:
|
||||
return inner.get("pagination")
|
||||
return None
|
||||
|
||||
async def _get_company_id(self) -> Optional[str]:
|
||||
result = await self.db.execute(
|
||||
select(Tenant.digital_twin_company_id).where(Tenant.id == self.tenant_id)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
async def fetch_remote_equipment(self) -> list[dict]:
|
||||
if not self.api_url:
|
||||
return []
|
||||
try:
|
||||
company_id = await self._get_company_id()
|
||||
if not company_id:
|
||||
logger.warning(
|
||||
f"Tenant {self.tenant_id} has no digital_twin_company_id mapped"
|
||||
)
|
||||
return []
|
||||
|
||||
all_equipment: list[dict] = []
|
||||
page = 1
|
||||
max_limit = 500
|
||||
@@ -113,7 +126,11 @@ class EquipmentSyncService:
|
||||
while True:
|
||||
resp = await client.get(
|
||||
"/api/v1/aas/equipment",
|
||||
params={"page": page, "limit": max_limit},
|
||||
params={
|
||||
"page": page,
|
||||
"limit": max_limit,
|
||||
"companyId": company_id,
|
||||
},
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
|
||||
Reference in New Issue
Block a user