You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/services/admins/competition_basic_setting_s...

39 lines
1.2 KiB

5 years ago
class Admins::CompetitionBasicSettingService < ApplicationService
attr_reader :competition, :params
def initialize(competition, params)
@params = params
@competition = competition
end
def call
ActiveRecord::Base.transaction do
competition.name = strip params[:name]
competition.sub_title = strip params[:sub_title]
competition.start_time = params[:start_time]
5 years ago
competition.end_time = params[:end_time]
competition.mode = params[:mode]
5 years ago
competition.identifier = strip params[:identifier]
5 years ago
competition.bonus = params[:bonus]
competition.awards_count = params[:awards_count]
competition.description = strip params[:description]
5 years ago
5 years ago
competition.save!
if competition.mode == 1 || competition.mode == 4
competition.competition_mode_setting&.destroy
5 years ago
else
setting = competition.competition_mode_setting || CompetitionModeSetting.create!(competition_id: competition.id)
if competition.mode == 2
setting.course_id = params[:course_id]
elsif competition.mode == 3
setting.start_time = params[:teach_start_time]
setting.end_time = params[:teach_end_time]
end
setting.save!
5 years ago
end
5 years ago
competition
5 years ago
end
end
end