def create_campaign(campaign_dto: NewCampaignDTO):
     campaign = Campaign.from_dto(campaign_dto)
     campaign.create()
     if campaign_dto.organisations:
         for org_id in campaign_dto.organisations:
             organisation = OrganisationService.get_organisation_by_id(
                 org_id)
             campaign.organisation.append(organisation)
         db.session.commit()
     return campaign
    def create_campaign(campaign_dto: NewCampaignDTO):
        campaign = Campaign.from_dto(campaign_dto)
        try:
            campaign.create()
            if campaign_dto.organisations:
                for org_id in campaign_dto.organisations:
                    organisation = OrganisationService.get_organisation_by_id(org_id)
                    campaign.organisation.append(organisation)
                db.session.commit()
        except IntegrityError as e:
            current_app.logger.info("Integrity error: {}".format(e.args[0]))
            raise ValueError()

        return campaign
 def create_campaign(campaign_dto: NewCampaignDTO):
     """ Creates a new campaign """
     campaign = Campaign.from_dto(campaign_dto)
     try:
         campaign.create()
         if campaign_dto.organisations:
             for org_id in campaign_dto.organisations:
                 organisation = OrganisationService.get_organisation_by_id(
                     org_id)
                 campaign.organisation.append(organisation)
             db.session.commit()
     except IntegrityError as e:
         current_app.logger.info("Integrity error: {}".format(e.args[0]))
         if isinstance(e.orig, UniqueViolation):
             raise ValueError("Campaign name already exists") from e
         if isinstance(e.orig, NotNullViolation):
             raise ValueError("Campaign name cannot be null") from e
     return campaign