Fakultas Ilmu Komputer UI

Commit fb02ae4b authored by Glenda Emanuella Sutanto's avatar Glenda Emanuella Sutanto
Browse files

[REFACTOR] Only displayed last active cart in user auth serializer

parent a52663a9
Pipeline #82940 passed with stages
in 12 minutes and 7 seconds
import datetime
from django.contrib.auth.models import Group
from rest_framework import serializers, exceptions
from dj_rest_auth.serializers import LoginSerializer
......@@ -23,12 +24,15 @@ class UserAuthSerializer(serializers.ModelSerializer):
if instance.is_staff:
result['role'] = 'admin'
result['transaction_status'] = None
result['cart_id'] = None
if instance.cart.exists():
result['transaction_status'] = instance.cart.last().transaction_status
result['cart_id'] = instance.cart.last().id
result['transaction_status'] = None
result['cart_id'] = None
active_carts = instance.cart.filter(program_end_date__gte=datetime.date.today())
if len(active_carts) > 0:
last_active_cart = active_carts.order_by('-id')[0]
result['transaction_status'] = last_active_cart.transaction_status
result['cart_id'] = last_active_cart.id
return result
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment