Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullai-t committed Dec 5, 2023
1 parent e8513d7 commit 3fa60fb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/api/store/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ def create_campaign(self, context: Context, args) -> Tuple[dict, MassEnergizeAPI
contact_image = args.pop('image', None)
contact_phone = args.get('phone_number', None)

campaigns = Campaign.objects.filter(title=title, campaign_account__id=campaign_account_id, is_deleted=False)

owner = get_user_from_context(context)
if not owner:
return None, CustomMassenergizeError("User not found")

campaigns = Campaign.objects.filter(title=title, owner=owner, is_deleted=False)
if campaigns:
return campaigns.first(), None

new_campaign = Campaign.objects.create(**args)

new_campaign.owner = owner


if campaign_account_id:
account = CampaignAccount.objects.get(id=campaign_account_id)
Expand All @@ -81,19 +88,13 @@ def create_campaign(self, context: Context, args) -> Tuple[dict, MassEnergizeAPI
media = Media.objects.create(name=name, file=logo)
new_campaign.logo = media


owner = get_user_from_context(context)
if not owner:
return None, CustomMassenergizeError("User not found")

new_campaign.owner = owner


if contact_email:
user = UserProfile.objects.filter(email=contact_email).first()
key_manager = CampaignManager()
key_manager.is_key_contact = True
key_manager.campaign = new_campaign
key_manager.contact = contact_phone
if user:
key_manager.user = user
else:
Expand Down

0 comments on commit 3fa60fb

Please sign in to comment.