Fix map layout jump, CRM/edit distributeurs, progress overlay.
Stable map grid, no fitBounds on world view, entity PATCH edit form, CRM buttons on distributors, and loading animation for sync/wait states.
This commit is contained in:
@@ -10,7 +10,7 @@ from typing import Any, Optional
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.db import execute, execute_returning, fetch_all, fetch_one
|
||||
from app.export_halal_scoring import COUNTRY_HALAL_MARKET, halal_pin_tier, score_entity
|
||||
@@ -139,6 +139,24 @@ class EntityIdsIn(BaseModel):
|
||||
entity_ids: list[int]
|
||||
|
||||
|
||||
|
||||
|
||||
class EntityUpdateIn(BaseModel):
|
||||
name: Optional[str] = None
|
||||
entity_type: Optional[str] = None
|
||||
country_iso2: Optional[str] = None
|
||||
city: Optional[str] = None
|
||||
address_line: Optional[str] = None
|
||||
postal_code: Optional[str] = None
|
||||
phone: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
website: Optional[str] = None
|
||||
volume_band: Optional[str] = None
|
||||
pipeline_stage: Optional[str] = None
|
||||
confidence: Optional[int] = Field(None, ge=0, le=100)
|
||||
halal_cert_notes: Optional[str] = None
|
||||
cold_chain: Optional[bool] = None
|
||||
|
||||
class FavoritesIn(BaseModel):
|
||||
entity_ids: list[int]
|
||||
favorite: bool = True
|
||||
@@ -428,6 +446,30 @@ def export_contacts_csv(
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@router.patch("/entities/{entity_id}")
|
||||
def update_entity(entity_id: int, payload: EntityUpdateIn) -> dict[str, Any]:
|
||||
row = fetch_one("SELECT id FROM export_market_entities WHERE id = %s", (entity_id,))
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Entity not found")
|
||||
|
||||
data = payload.model_dump(exclude_unset=True)
|
||||
if not data:
|
||||
raise HTTPException(status_code=400, detail="Geen velden om bij te werken")
|
||||
if "country_iso2" in data and data["country_iso2"]:
|
||||
data["country_iso2"] = data["country_iso2"].upper()[:2]
|
||||
|
||||
sets = [f"{k} = %s" for k in data]
|
||||
sets.append("updated_at = NOW()")
|
||||
params = list(data.values()) + [entity_id]
|
||||
execute(
|
||||
f"UPDATE export_market_entities SET {', '.join(sets)} WHERE id = %s",
|
||||
tuple(params),
|
||||
)
|
||||
_MAP_CACHE.clear()
|
||||
return get_entity(entity_id)
|
||||
|
||||
@router.post("/entities/{entity_id}/contacts")
|
||||
def add_contact(entity_id: int, payload: ContactCreateIn) -> dict[str, Any]:
|
||||
ent = fetch_one("SELECT id FROM export_market_entities WHERE id = %s", (entity_id,))
|
||||
@@ -691,6 +733,8 @@ def map_bundle(
|
||||
"email": row.get("email") or row.get("contact_email"),
|
||||
"phone": row.get("phone") or row.get("contact_phone"),
|
||||
"halal_score": h_score,
|
||||
"client_id": row.get("client_id"),
|
||||
"is_favorite": bool(row.get("is_favorite")),
|
||||
"has_contact": bool(
|
||||
row.get("email") or row.get("contact_email")
|
||||
or row.get("phone") or row.get("contact_phone")
|
||||
|
||||
Reference in New Issue
Block a user