"""Shared helpers for resolving the department that owns a given task type.""" from typing import Optional def find_owning_department(db_project, task_type: str) -> Optional[str]: """Return the name of the department (standard or custom) whose task_types list contains task_type for this project, or None if no department owns it.""" if not task_type: return None from routers.projects import STANDARD_DEPARTMENTS for department in STANDARD_DEPARTMENTS: if task_type in department["task_types"]: return department["name"] for department in (db_project.custom_departments or []): if task_type in department.get("task_types", []): return department["name"] return None