From 3481a373f0b2bf35bb1bf998809a6929157db9c3 Mon Sep 17 00:00:00 2001 From: MustafaMunir123 Date: Fri, 15 Dec 2023 09:01:38 +0500 Subject: [PATCH] chore: update --- apps/transactions/api/v1/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/transactions/api/v1/views.py b/apps/transactions/api/v1/views.py index 0a03551..b83acab 100644 --- a/apps/transactions/api/v1/views.py +++ b/apps/transactions/api/v1/views.py @@ -28,10 +28,13 @@ def get_serializer(): def post(self, request): try: user = request.user + print("Boss") serializer = self.get_serializer() serializer = serializer(data=request.data) + print("Toss") serializer.is_valid(raise_exception=True) serializer.save(user=user) + print("Loss") return success_response(data=serializer.validated_data, status=status.HTTP_200_OK) except Exception as ex: raise ex @@ -70,11 +73,12 @@ def post(self, request): return success_response(status=status.HTTP_200_OK, data=f"transaction with id {entry_no} updated.") last_transaction = Transaction.objects.last() - last_entry = last_transaction.entry_no - if entry_no != last_entry + 1: - return success_response( - status=status.HTTP_400_BAD_REQUEST, success=False, data="invalid transaction id" - ) + if last_transaction: + last_entry = last_transaction.entry_no + if entry_no != last_entry + 1: + return success_response( + status=status.HTTP_400_BAD_REQUEST, success=False, data="invalid transaction id" + ) to_account = request.data.pop("to_account", None) from_account = request.data.pop("from_account", None)