2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
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]
|
2020-05-21 18:52:24 +00:00
|
|
|
return campaign
|
2018-11-09 00:29:00 +00:00
|
|
|
else
|
|
|
|
profile_id = params[:campaign][:profile_id]
|
2020-05-20 21:03:16 +00:00
|
|
|
Profile.find(profile_id).update params[:profile]
|
2018-11-09 00:29:00 +00:00
|
|
|
return CreatePeerToPeerCampaign.create(params[:campaign], profile_id)
|
|
|
|
end
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|