Skip to content

Commit

Permalink
update user module
Browse files Browse the repository at this point in the history
  • Loading branch information
50-Course committed May 3, 2024
1 parent 71aa827 commit fa35a80
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 7 deletions.
15 changes: 8 additions & 7 deletions backend/paycheck/src/paycheck/IAM/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class User(AbstractUser):
null=False,
)

REQUIRED_FIELDS = ["email"]
REQUIRED_FIELDS = ["first_name", "last_name"]
USERNAME_FIELD = "email"

objects = models.Manager()
Expand All @@ -56,9 +56,13 @@ class UserType(models.TextChoices):
CUSTOMER_SUPPORT = "Customer Support"
ADMIN = "Admin"

user = models.OneToOneField(
"User", on_delete=models.CASCADE, related_name="profile"
)

class Customer(UserProfile):
"""
Represents a customer of the platform.
"""

user = models.ForeignKey("User", on_delete=models.CASCADE, related_name="profile")

phone_number = models.CharField(
max_length=20, blank=True, null=True, help_text=_("Phone number of the user")
Expand Down Expand Up @@ -105,9 +109,6 @@ class UserType(models.TextChoices):
help_text=_("Document to verify the user"),
)

def full_name(self) -> str:
return f"{self.user}"

def __str__(self) -> str:
return f"{self.full_name()} - {self.user_type}"

Expand Down
87 changes: 87 additions & 0 deletions backend/paycheck/src/paycheck/IAM/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from .models import SupportUser, Adminuser, Customer, UserProfile, UserProofile, User
from django.contrib.auth import get_user_model
from rest_framework import serializers

UserModel - get_user_model()


class UserSerializer(serializers.Serializer):
"""
User serializers is the base serializer for all user types
It provides the barest important information that is allowed to be shared
"""

first_name = serializers.CharField(max_length=40)
last_name = serializers.CharField(max_length=40)
email_address = serializers.EmailField()
phone_number = serializers.CharField(max_length=20)

class Meta:
model = User
exclude = [
"password",
"is_staff",
"is_superuser",
"is_active",
"date_joined",
"last_login",
"groups",
"user_permissions",
]
read_only_fields = ["id"]


class CustomerSerializer(serializers.Serializer):
"""
Customer serializer provides the information about the customer that is allowed to be shared over
API contracts and integrations
"""

user = UserSerializer()
date_of_birth = serializers.DateField()
photo_id = serializers.ImageField()

full_name = serializers.SerializerMethodField()

def get_full_name(self) -> str:
pass

class Meta:
model = Customer
fields = ["user", "date_of_birth", "photo_id"]
exclude = ["user", "bvn", "nin"]


class SupportUserSerializer(serializers.ModelSerializer):
"""
Shares the information regarding a member of our internal platform from the support team
that can moderate or interact with a user
"""

class Meta:
model = SupportUser


class AdminSerializer(serializers.ModelSerializer):
"""
Shares the information regarding a member of our internal platform from the admin team
that can manage a user or anyone on the platform
"""

class Meta:
model = Adminuser


class UserProfileWriteSerializer(serializers.Serializer):
"""
Defines the information that can be written to the user profile
"""

user = UserSerializer()

def create(self, *args, **kwargs) -> None:
pass

def update(self, instance, validated_data):
self.user = UserModel.objects.get(id=validated_data.get("user").get("id"))

0 comments on commit fa35a80

Please sign in to comment.