Skip to content

Commit

Permalink
Handled isBundle in SF call
Browse files Browse the repository at this point in the history
  • Loading branch information
sab-LC committed Oct 14, 2024
1 parent dc61913 commit e0a1b86
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/versioned/v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ def post(self, request):
end_date = request.data.get('end_date')
date_last_updated = request.data.get('date_last_updated')
subscription_type = request.data.get('subscription_type')
isBundle = request.data.get('isBundle')

account_type_to_field = {
'i': 'institution_id',
Expand Down Expand Up @@ -409,12 +410,12 @@ def post(self, request):
}
with transaction.atomic():
subscription, created = Subscription.objects.get_or_create(**filter_kwargs)
if created:
if created and not isBundle:
subscriber = get_object_or_404(model_class, id=hub_id)
subscriber.is_subscribed = True
subscriber.save()
return Response({'success': 'The record is created.'}, status=HTTP_201_CREATED)
else:
elif isBundle:
subscription.users_count = user_count
subscription.api_key_count = api_key_count
subscription.project_count = project_count
Expand All @@ -425,6 +426,8 @@ def post(self, request):
subscription.subscription_type = mapped_subscription_type
subscription.save()
return Response({'success': 'The record is updated.'},status=HTTP_200_OK)
else:
return Response({'error': 'Failed to create Subscription. Invalid subscrption arguments provided.'}, status=status.HTTP_400_BAD_REQUEST)

except IntegrityError as e:
if 'violates foreign key constraint' in str(e):
Expand Down

0 comments on commit e0a1b86

Please sign in to comment.