From 8857da106365715af0d000ce79d4183e921deab5 Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Fri, 24 Jan 2025 15:18:17 +0400 Subject: [PATCH] feat: setting parent for department section --- services/department.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/services/department.py b/services/department.py index a42eb9c..15f574c 100644 --- a/services/department.py +++ b/services/department.py @@ -129,15 +129,17 @@ class DepartmentService(BaseService): section = await self._get_section_by_id(request.section.id) if not section: return UpdateDepartmentSectionResponse(ok=False, message=f"Отдел с ID {request.section.id} не найден") - if section.name != request.section.name: - section_same_name = await self._get_section_by_name( - request.section.name, - department_id=request.section.department_id, - parent_section_id=request.section.parent_department_section_id, - ) - if section_same_name: - return UpdateDepartmentSectionResponse(ok=False, message="Отдел с данным именем уже существует") + section_same_name = await self._get_section_by_name( + request.section.name, + department_id=request.section.department_id, + parent_section_id=request.section.parent_department_section_id, + ) + if section_same_name: + return UpdateDepartmentSectionResponse(ok=False, message="Отдел с данным именем уже существует") + + section.parent_department_section_id = request.section.parent_department_section_id + section.department_id = request.section.department_id section.name = request.section.name await self.session.commit() return UpdateDepartmentSectionResponse(ok=True, message="Отдел успешно изменен")