houdini/lib/create/create_campaign.rb

24 lines
862 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2020-06-12 20:03:43 +00:00
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
module CreateCampaign
CAMPAIGN_NAME_LENGTH_LIMIT = 60
2018-11-09 00:29:00 +00:00
# @return [Object] a json object for historical purposes
def self.create(params, nonprofit)
Time.use_zone(nonprofit.timezone || 'UTC') do
params[:campaign][:end_datetime] = Chronic.parse(params[:campaign][:end_datetime]) if params[:campaign][:end_datetime].present?
end
if !params[:campaign][:parent_campaign_id]
campaign = nonprofit.campaigns.create params[:campaign]
return campaign
2018-11-09 00:29:00 +00:00
else
profile_id = params[:campaign][:profile_id]
Profile.find(profile_id).update params[:profile]
2018-11-09 00:29:00 +00:00
return CreatePeerToPeerCampaign.create(params[:campaign], profile_id)
end
end
end