feat(staff): action buttons → filtered customer/group list

Adds groups.user_id filter; viewCustomers/viewGroups push owner_account_id query; CustomerList/GroupList read it.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-05 19:06:27 +08:00
parent 02a709ba93
commit dfdd0595d2
6 changed files with 109 additions and 21 deletions
+23
View File
@@ -21,6 +21,7 @@ async def _seed(session: AsyncSession) -> None:
room_name="Team A",
owner_account_id="wx_owner_1",
owner_account_nickname="WxOne",
owner_user_id="u_wx_1",
member_count=2,
message_count=10,
last_chat_time=2000,
@@ -30,6 +31,7 @@ async def _seed(session: AsyncSession) -> None:
channel="wechat",
room_name="Team B",
owner_account_id="wx_owner_2",
owner_user_id="u_wx_2",
member_count=1,
last_chat_time=1000,
),
@@ -38,6 +40,7 @@ async def _seed(session: AsyncSession) -> None:
channel="whatsapp",
room_name="WA Team",
owner_account_id="wa_owner_1",
owner_user_id="u_wa_1",
member_count=3,
last_chat_time=None,
),
@@ -176,6 +179,26 @@ async def test_filter_by_owner_account_id(make_client):
assert body["items"][0]["room_id"] == "room_a@chatroom"
async def test_filter_by_user_id(make_client):
"""``?user_id=u_wx_1`` -> only Team A (param maps to owner_user_id column)."""
client = await make_client(_seed)
r = await client.get("/api/groups", params={"user_id": "u_wx_1"})
assert r.status_code == 200
body = r.json()
assert body["total"] == 1
assert body["items"][0]["room_id"] == "room_a@chatroom"
# Sanity: a different user_id matches a different single group.
r2 = await client.get("/api/groups", params={"user_id": "u_wa_1"})
assert r2.status_code == 200
body2 = r2.json()
assert body2["total"] == 1
assert body2["items"][0]["room_id"] == "wa_room_x@s.whatsapp.net"
# Sanity: an unknown user_id matches nothing.
r3 = await client.get("/api/groups", params={"user_id": "nobody"})
assert r3.status_code == 200
assert r3.json()["total"] == 0
async def test_pagination(make_client):
"""``page_size=1`` -> 1 item, total 3."""
client = await make_client(_seed)