46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
|
from aiogram.types import User as UserType
|
||
|
from peewee import Model
|
||
|
|
||
|
from .model import User as UserModel
|
||
|
from .model import Admin, Operator
|
||
|
from utils import types
|
||
|
|
||
|
|
||
|
class Register:
|
||
|
|
||
|
@classmethod
|
||
|
def __register_user(self, model: Model, user: UserType):
|
||
|
model.insert(
|
||
|
user_id=user.id,
|
||
|
first_name=user.first_name,
|
||
|
last_name=user.last_name,
|
||
|
username=user.username
|
||
|
).on_conflict_replace().execute()
|
||
|
|
||
|
@classmethod
|
||
|
def register_user(self, user: UserType):
|
||
|
return self.__register_user(UserModel, user)
|
||
|
|
||
|
@classmethod
|
||
|
def register_admin(self, user: UserType):
|
||
|
return self.__register_user(Admin, user)
|
||
|
|
||
|
@classmethod
|
||
|
def register_operator(self, user: UserType):
|
||
|
return self.__register_user(Operator, user)
|
||
|
|
||
|
|
||
|
class User:
|
||
|
|
||
|
@staticmethod
|
||
|
def get_user(user_id: int):
|
||
|
if not UserModel.select().where(UserModel.user_id==user_id).exists():
|
||
|
return None
|
||
|
data = UserModel.get(UserModel.user_id==user_id)
|
||
|
return types.User(
|
||
|
user_id=data.user_id,
|
||
|
first_name=data.first_name,
|
||
|
last_name=data.last_name,
|
||
|
username=data.username
|
||
|
)
|