fix / AEB-68 account type doesn't displayed correctly

This commit is contained in:
Timofey
2025-10-29 09:56:32 +03:00
parent 6ac5acebba
commit efc9d5c579
9 changed files with 184 additions and 178 deletions

View File

@@ -2,6 +2,7 @@ from typing import Any, Optional
from rest_framework import serializers
from django.conf import settings
from api.types import User
from sitemanagement.constants.account_types import account_types
class UserResponseSerializer(serializers.Serializer):
id = serializers.IntegerField(read_only=True)
@@ -14,6 +15,7 @@ class UserResponseSerializer(serializers.Serializer):
surname = serializers.CharField(source='last_name', read_only=True)
imageURL = serializers.SerializerMethodField()
uuid = serializers.SerializerMethodField()
account_type = serializers.SerializerMethodField()
class Meta:
ref_name = "UserResponse" # для OpenAPI
@@ -22,6 +24,10 @@ class UserResponseSerializer(serializers.Serializer):
"""Получает короткий UUID (первые 6 символов) из профиля пользователя"""
return obj.userprofile.short_uuid if hasattr(obj, 'userprofile') else None
def get_account_type(self, obj: User) -> Optional[str]:
"""Получает тип аккаунта пользователя"""
return obj.userprofile.get_account_type() if hasattr(obj, 'userprofile') else None
def get_imageURL(self, obj: User) -> Optional[str]:
"""Получает полный URL для изображения профиля пользователя"""
try:
@@ -44,6 +50,7 @@ class UserResponseSerializer(serializers.Serializer):
'name': data['name'], # str
'surname': data['surname'], # str
'imageURL': data['imageURL'], # Optional[str]
'account_type': data['account_type'], # AccountTypeLiteral
'uuid': data['uuid'], # Optional[str]
}
@@ -60,6 +67,11 @@ class LoginRequestSerializer(serializers.Serializer):
required=True,
style={'input_type': 'password'}
)
role = serializers.ChoiceField(
help_text="Роль пользователя",
choices=account_types,
required=False
)
class LoginResponseSerializer(serializers.Serializer):