Files
shopship/apps/account/api/selectors.py
T
2026-08-24 15:54:08 +03:30

32 lines
885 B
Python

from rest_framework_simplejwt.tokens import RefreshToken
from apps.account.models import User
class UserSelector:
@staticmethod
def get_user_profile(user: User) -> dict:
return {
"id": user.id,
"phone": user.phone,
"name": user.name,
"state": user.state,
"created_at": user.created_at,
}
@staticmethod
def get_tokens_for_user(user: User) -> dict:
refresh = RefreshToken.for_user(user)
return {
"refresh": str(refresh),
"access": str(refresh.access_token),
}
@staticmethod
def get_token_response(user: User) -> dict:
return {
"message": "ورود با موفقیت انجام شد.",
"tokens": UserSelector.get_tokens_for_user(user),
"user": UserSelector.get_user_profile(user),
}