44from fastapi .responses import JSONResponse
55
66from api import api_call , set_additional_data
7- from utils import get_current_time , normalize_items , str_to_list , list_to_str
7+ from utils import get_current_time , normalize_items , str_to_list , list_to_str , remove_sn
88
99router = APIRouter (prefix = '/task' )
1010
@@ -13,6 +13,10 @@ def api_get_task(id: int, get_employee_names: bool = True):
1313 task = api_call ('task' , 'show' , f'id={ id } ' ).get ('data' )
1414 if task is None :
1515 return JSONResponse ({'status' : 'fail' , 'detail' : 'task not found' }, 404 )
16+
17+ customer = api_call ('customer' , 'get_data' , f'id={ task ["customer" ][0 ]} ' )['data' ] if 'customer' in task else None
18+
19+
1620 return {
1721 'status' : 'success' ,
1822 'data' : {
@@ -80,7 +84,10 @@ def api_get_task(id: int, get_employee_names: bool = True):
8084 'apartment' : unescape (task ['address' ]['apartment' ])
8185 if task ['address' ].get ('apartment' ) else None
8286 },
83- 'customer' : task ['customer' ][0 ] if 'customer' in task else None ,
87+ 'customer' : {
88+ 'id' : customer ['id' ],
89+ 'name' : remove_sn (customer ['full_name' ])
90+ } if customer else None ,
8491 'employees' : list (task .get ('staff' , {}).get ('employee' , {}).values ()),
8592 'divisions' : list (task .get ('staff' , {}).get ('division' , {}).values ()),
8693 }
@@ -165,6 +172,7 @@ def api_get_tasks(
165172 tasks_data = []
166173 if get_data :
167174 for task in normalize_items (api_call ('task' , 'show' , f'id={ list_to_str (tasks )} ' )):
175+ customer = api_call ('customer' , 'get_data' , f'id={ task ["customer" ][0 ]} ' )['data' ] if 'customer' in task else None
168176 tasks_data .append ({
169177 'id' : task ['id' ],
170178 'comments' : [
@@ -230,7 +238,10 @@ def api_get_tasks(
230238 'apartment' : unescape (task ['address' ]['apartment' ])
231239 if task ['address' ].get ('apartment' ) else None
232240 },
233- 'customer' : task ['customer' ][0 ] if 'customer' in task else None ,
241+ 'customer' : {
242+ 'id' : customer ['id' ],
243+ 'name' : remove_sn (customer ['full_name' ])
244+ } if customer else None ,
234245 'employees' : list (task .get ('staff' , {}).get ('employee' , {}).values ()),
235246 'divisions' : list (task .get ('staff' , {}).get ('division' , {}).values ()),
236247 })
0 commit comments