diff --git a/app/modules/sag/backend/router.py b/app/modules/sag/backend/router.py index e473006..47a50f0 100644 --- a/app/modules/sag/backend/router.py +++ b/app/modules/sag/backend/router.py @@ -161,6 +161,14 @@ def _validate_group_id(group_id: Optional[int], field_name: str = "assigned_grou if not exists: raise HTTPException(status_code=400, detail=f"Invalid {field_name}") + +def _validate_customer_id(customer_id: Optional[int], field_name: str = "customer_id") -> None: + if customer_id is None: + return + exists = execute_query("SELECT 1 FROM customers WHERE id = %s", (customer_id,)) + if not exists: + raise HTTPException(status_code=400, detail=f"Invalid {field_name}") + # ============================================================================ # QUICKCREATE AI ANALYSIS # ============================================================================ @@ -973,6 +981,9 @@ async def update_sag(sag_id: int, updates: dict): if "assigned_group_id" in updates: updates["assigned_group_id"] = _coerce_optional_int(updates.get("assigned_group_id"), "assigned_group_id") _validate_group_id(updates["assigned_group_id"]) + if "customer_id" in updates: + updates["customer_id"] = _coerce_optional_int(updates.get("customer_id"), "customer_id") + _validate_customer_id(updates["customer_id"]) # Build dynamic update query allowed_fields = [ @@ -980,6 +991,7 @@ async def update_sag(sag_id: int, updates: dict): "beskrivelse", "template_key", "status", + "customer_id", "ansvarlig_bruger_id", "assigned_group_id", "priority", diff --git a/app/modules/sag/templates/detail.html b/app/modules/sag/templates/detail.html index e5e5ee7..e8d7c41 100644 --- a/app/modules/sag/templates/detail.html +++ b/app/modules/sag/templates/detail.html @@ -2376,9 +2376,19 @@
@@ -2608,6 +2618,9 @@