38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import pydantic
|
|
|
|
from app.storage.mongo import database
|
|
from bson import codec_options
|
|
|
|
|
|
collection = database.get_collection("staff", codec_options=codec_options.CodecOptions(tz_aware=True))
|
|
|
|
|
|
class Staff(pydantic.BaseModel):
|
|
platform_id: int
|
|
vk_id: int|None = None
|
|
yandex_id: int|None = None
|
|
telegram_id: int|None = None
|
|
email: str|None = None
|
|
|
|
|
|
async def create(staff: Staff) -> str:
|
|
result = await collection.insert_one(staff.model_dump())
|
|
return result.inserted_id
|
|
|
|
|
|
async def update(platform_id: int, vk_id: int|None, yandex_id: int|None, telegram_id: int|None, email: str|None) -> bool:
|
|
result = await collection.update_one({'platform_id': platform_id}, {'$set': {'vk_id': vk_id, 'yandex_id': yandex_id, 'telegram_id': telegram_id, 'email': email}})
|
|
return result.modified_count != 0
|
|
|
|
|
|
async def delete(platform_id: int) -> bool:
|
|
result = await collection.delete_one({'platform_id': platform_id})
|
|
return result.deleted_count != 0
|
|
|
|
|
|
async def get() -> list[Staff]:
|
|
result = []
|
|
async for item in collection.find({}):
|
|
result.append(Staff.model_validate(item))
|
|
return result
|