Skip to content

Commit

Permalink
feat: fix serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Oct 3, 2024
1 parent fcb2832 commit a36c3a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions chats/apps/api/v1/rooms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ class ListOptimizedRoomSerializer(serializers.ModelSerializer):
is_waiting = serializers.CharField(
read_only=True, source="is_waiting_combined"
) # precisa mesmo verificar flowstarts? o campo is_waiting deveria ser o suficiente para essa feature
is_24h_valid = serializers.BooleanField(default=True)
is_24h_valid = serializers.BooleanField(
default=True, source="is_24h_valid_computed"
)
last_interaction = serializers.DateTimeField(read_only=True)
can_edit_custom_fields = serializers.SerializerMethodField()

Expand All @@ -174,11 +176,18 @@ class Meta:
]

def get_user(self, room: Room):
return {
"first_name": room.user.first_name,
"last_name": room.user.last_name,
"email": room.user.email,
}
try:
return {
"first_name": room.user.first_name,
"last_name": room.user.last_name,
"email": room.user.email,
}
except AttributeError:
{
"first_name": "",
"last_name": "",
"email": "",
}

def get_contact(self, room: Room):
return {
Expand Down
2 changes: 1 addition & 1 deletion chats/apps/api/v1/rooms/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_queryset(self): # separar queries list e retrieve de update e close
last_contact_interaction=Max(
"messages__created_on", filter=Q(messages__contact__isnull=False)
),
is_24h_valid=Case(
is_24h_valid_computed=Case(
When(
Q(
urn__startswith="whatsapp",
Expand Down

0 comments on commit a36c3a7

Please sign in to comment.