Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions todo/services/task_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,21 @@ def prepare_task_dto(cls, task_model: TaskModel, user_id: str = None) -> TaskDTO
def _prepare_label_dtos(cls, label_ids: List[str]) -> List[LabelDTO]:
label_models = LabelRepository.list_by_ids(label_ids)

def prepare_label_user_dto(user_id: str) -> UserDTO:
if user_id == "system":
return UserDTO(id="system", name="System")
else:
return cls.prepare_user_dto(user_id)

return [
LabelDTO(
id=str(label_model.id),
name=label_model.name,
color=label_model.color,
createdAt=label_model.createdAt,
updatedAt=label_model.updatedAt if hasattr(label_model, "updatedAt") else None,
createdBy=cls.prepare_user_dto(label_model.createdBy),
updatedBy=cls.prepare_user_dto(label_model.updatedBy)
createdBy=prepare_label_user_dto(label_model.createdBy) if label_model.createdBy else None,
updatedBy=prepare_label_user_dto(label_model.updatedBy)
if hasattr(label_model, "updatedBy") and label_model.updatedBy
else None,
)
Expand Down Expand Up @@ -391,7 +397,8 @@ def create_task(cls, dto: CreateTaskDTO) -> CreateTaskResponse:
raise ValueError(f"Team not found: {assignee_id}")

if dto.labels:
existing_labels = LabelRepository.list_by_ids(dto.labels)
label_object_ids = [PyObjectId(label_id) for label_id in dto.labels]
existing_labels = LabelRepository.list_by_ids(label_object_ids)
if len(existing_labels) != len(dto.labels):
found_ids = [str(label.id) for label in existing_labels]
missing_ids = [label_id for label_id in dto.labels if label_id not in found_ids]
Expand All @@ -410,13 +417,15 @@ def create_task(cls, dto: CreateTaskDTO) -> CreateTaskResponse:
)
)

task_labels = [PyObjectId(label_id) for label_id in dto.labels] if dto.labels else []

task = TaskModel(
id=None,
title=dto.title,
description=dto.description,
priority=dto.priority,
status=dto.status,
labels=dto.labels,
labels=task_labels,
dueAt=dto.dueAt,
startedAt=started_at,
createdAt=now,
Expand Down
Loading