Commit fddd97e3 authored by uuo00_n's avatar uuo00_n

feat(persons): 添加按类型统计的功能并返回分项计数

在获取人员列表时,现在会额外统计每种类型的人数并返回
parent f1739a61
......@@ -31,8 +31,12 @@ async def bulk_create(persons: List[PersonCreate], current_user: dict = Depends(
)
async def list_persons(current_user: dict = Depends(require_role(3))):
res = []
counts = {}
cursor = db.db.persons.find({}).sort("person_id", 1)
async for d in cursor:
d["_id"] = str(d["_id"])
res.append(d)
return res
\ No newline at end of file
t = d.get("type")
if t:
counts[t] = counts.get(t, 0) + 1
return {"items": res, "counts_by_type": counts}
\ No newline at end of file
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