Commit befb2764 authored by uuo00_n's avatar uuo00_n

fix(dashboard): 确保teacher_person_id和created_at的正确格式

修复teacher_person_id可能为字符串时的ObjectId转换问题
确保created_at字段返回ISO格式的字符串
parent 6d17b883
...@@ -205,6 +205,9 @@ async def homeroom_current_summary(current_user: Dict[str, Any]) -> Dict[str, An ...@@ -205,6 +205,9 @@ async def homeroom_current_summary(current_user: Dict[str, Any]) -> Dict[str, An
teacher = await _get_teacher_entity(current_user["_id"], binding) teacher = await _get_teacher_entity(current_user["_id"], binding)
teacher_person_id = teacher.get("person_id") teacher_person_id = teacher.get("person_id")
if isinstance(teacher_person_id, str) and ObjectId.is_valid(teacher_person_id):
teacher_person_id = ObjectId(teacher_person_id)
classes = [] classes = []
# 使用 person_id 查询班级 # 使用 person_id 查询班级
cursor = db.db.classes.find({"head_teacher_person_id": teacher_person_id}) cursor = db.db.classes.find({"head_teacher_person_id": teacher_person_id})
...@@ -255,7 +258,7 @@ async def homeroom_current_summary(current_user: Dict[str, Any]) -> Dict[str, An ...@@ -255,7 +258,7 @@ async def homeroom_current_summary(current_user: Dict[str, Any]) -> Dict[str, An
async for d in cursor: async for d in cursor:
directives.append({ directives.append({
"content": d.get("content"), "content": d.get("content"),
"created_at": d.get("created_at"), "created_at": d.get("created_at").isoformat() if isinstance(d.get("created_at"), datetime) else d.get("created_at"),
}) })
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment