competition module update api modify

dev_forum
p31729568 5 years ago
parent 44561b8a51
commit 02b0851e38

@ -15,7 +15,17 @@ class Competitions::CompetitionModulesController < Competitions::BaseController
md = current_module.competition_module_md_content || current_module.build_competition_module_md_content
md.name = params[:md_name]
md.content = params[:md_content]
md.save!
ActiveRecord::Base.transaction do
md.save!
attachment_ids = Array.wrap(params[:attachment_ids]).map(&:to_i)
old_attachment_ids = md.attachments.pluck(:id)
destroy_ids = old_attachment_ids - attachment_ids
md.attachments.where(id: destroy_ids).delete_all
Attachment.where(id: attachment_ids - old_attachment_ids).update_all(container: md)
end
render_ok
end

@ -10,13 +10,13 @@ module Searchable::Dependents::User
def check_searchable_dependents
if firstname_previously_changed? || lastname_previously_changed? || user_extension.school_id_previously_changed?
# reindex shixun
created_shixuns.each{ |shixun| shixun.reindex }
created_shixuns.each(&:reindex)
# reindex course
manage_courses.each(&:reindex)
# reindex subject
created_subjects.each { |subject| subject.reindex }
created_subjects.each(&:reindex)
end
end
end

@ -5,4 +5,7 @@ if md.present?
json.md_name md.name
json.md_content md.content
json.created_at md.created_at.strftime('%Y-%m-%d %H:%M:%S')
json.attachments do
json.array! md.attachments, partial: 'attachments/attachment_simple', as: :attachment
end
end
Loading…
Cancel
Save