fix(workbench): remove synthetic check projections
This commit is contained in:
@@ -5,7 +5,7 @@ from uuid import UUID
|
||||
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, model_validator
|
||||
|
||||
from app.domain.schemas.shared import ObjectRef, TimeRange, WireDateTime
|
||||
from app.domain.schemas.workbench_runtime import WorkbenchRuntimeWorkOrderSubtask
|
||||
from app.domain.schemas.workbench_runtime import WorkOrderActivity
|
||||
|
||||
Text = Annotated[str, Field(min_length=1, max_length=4000)]
|
||||
PositiveInt = Annotated[StrictInt, Field(ge=1)]
|
||||
@@ -122,18 +122,6 @@ WorkOrderStatus = Literal[
|
||||
]
|
||||
Priority = Literal["low", "normal", "high", "urgent"]
|
||||
WorkOrderType = Literal["general", "water_quality_complaint", "burst_report"]
|
||||
WorkOrderSubtasks = Annotated[
|
||||
list[WorkbenchRuntimeWorkOrderSubtask], Field(min_length=1, max_length=50)
|
||||
]
|
||||
|
||||
|
||||
def _validate_unique_subtasks(
|
||||
subtasks: list[WorkbenchRuntimeWorkOrderSubtask] | None,
|
||||
) -> None:
|
||||
if subtasks is not None and len({item.id for item in subtasks}) != len(subtasks):
|
||||
raise ValueError("work order subtask ids must be unique")
|
||||
|
||||
|
||||
class CreateWorkOrder(Model):
|
||||
request_id: UUID
|
||||
title: Annotated[str, Field(min_length=1, max_length=200)]
|
||||
@@ -145,13 +133,12 @@ class CreateWorkOrder(Model):
|
||||
work_order_type: WorkOrderType = "general"
|
||||
location: Annotated[str, Field(min_length=1, max_length=200)] | None = None
|
||||
scenario_code: Annotated[str, Field(min_length=1, max_length=128)] | None = None
|
||||
subtasks: WorkOrderSubtasks | None = None
|
||||
feedback_requirements: list[Text] = Field(default_factory=list)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def aware_schedule(self):
|
||||
if self.scheduled_at is not None and self.scheduled_at.tzinfo is None:
|
||||
raise ValueError("scheduled_at must include timezone")
|
||||
_validate_unique_subtasks(self.subtasks)
|
||||
return self
|
||||
|
||||
|
||||
@@ -170,8 +157,8 @@ class UpdateWorkOrder(Model):
|
||||
clear_location: StrictBool = False
|
||||
scenario_code: Annotated[str, Field(min_length=1, max_length=128)] | None = None
|
||||
clear_scenario_code: StrictBool = False
|
||||
subtasks: WorkOrderSubtasks | None = None
|
||||
clear_subtasks: StrictBool = False
|
||||
feedback_requirements: list[Text] | None = None
|
||||
progress_note: Text | None = None
|
||||
|
||||
@model_validator(mode="after")
|
||||
def valid_update(self):
|
||||
@@ -186,11 +173,8 @@ class UpdateWorkOrder(Model):
|
||||
raise ValueError("clear_location conflicts with location")
|
||||
if self.clear_scenario_code and self.scenario_code is not None:
|
||||
raise ValueError("clear_scenario_code conflicts with scenario_code")
|
||||
if self.clear_subtasks and self.subtasks is not None:
|
||||
raise ValueError("clear_subtasks conflicts with subtasks")
|
||||
if self.scheduled_at is not None and self.scheduled_at.tzinfo is None:
|
||||
raise ValueError("scheduled_at must include timezone")
|
||||
_validate_unique_subtasks(self.subtasks)
|
||||
return self
|
||||
|
||||
|
||||
@@ -217,12 +201,15 @@ class WorkOrder(Model):
|
||||
work_order_type: WorkOrderType = "general"
|
||||
location: str | None = None
|
||||
scenario_code: str | None = None
|
||||
subtasks: WorkOrderSubtasks | None = None
|
||||
feedback_requirements: list[str] = Field(default_factory=list)
|
||||
activity: list[WorkOrderActivity] = Field(default_factory=list)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def unique_subtasks(self):
|
||||
_validate_unique_subtasks(self.subtasks)
|
||||
return self
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def accept_legacy_document(cls, value):
|
||||
if isinstance(value, dict):
|
||||
return {key: item for key, item in value.items() if key != "subtasks"}
|
||||
return value
|
||||
|
||||
|
||||
class WorkOrderPage(Model):
|
||||
|
||||
Reference in New Issue
Block a user