Sha256: 45d8e9b5c47b52bef57f9fb6224087c85c4f5f4d1d25a2875ccef3c3ccb98f6e
Contents?: true
Size: 1.4 KB
Versions: 25
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true module Decidim module Budgets module Admin class UpdateProjectCategory < Decidim::Command include TranslatableAttributes # Public: Initializes the command. # # category_id - the category id to update # project_ids - the project ids to update. def initialize(category_id, project_ids) @category = Decidim::Category.find_by id: category_id @project_ids = project_ids @response = { category_name: "", successful: [], errored: [] } end def call return broadcast(:invalid_category) if @category.blank? return broadcast(:invalid_project_ids) if @project_ids.blank? @response[:category_name] = @category.translated_name Project.where(id: @project_ids).find_each do |project| if @category == project.category @response[:errored] << translated_attribute(project.title) else transaction do update_project_category project end @response[:successful] << translated_attribute(project.title) end end broadcast(:update_projects_category, @response) end private def update_project_category(project) project.update!( category: @category ) end end end end end
Version data entries
25 entries across 25 versions & 1 rubygems