video-stream/driver/database/dbusers.py
2022-02-05 10:28:59 +07:00

29 lines
692 B
Python

from typing import Dict, List, Union
from driver.database.dblocal import db
usersdb = db.users
async def is_served_user(user_id: int) -> bool:
user = await usersdb.find_one({"user_id": user_id})
if not user:
return False
return True
async def get_served_users() -> list:
users = usersdb.find({"user_id": {"$gt": 0}})
if not users:
return []
users_list = []
for user in await users.to_list(length=1000000000):
users_list.append(user)
return users_list
async def add_served_user(user_id: int):
is_served = await is_served_user(user_id)
if is_served:
return
return await usersdb.insert_one({"user_id": user_id})