scinote-web/app/services/repository_columns/update_column_service.rb

35 lines
848 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module RepositoryColumns
2019-10-16 21:07:46 +08:00
class UpdateColumnService < RepositoryColumns::ColumnService
def initialize(user:, team:, column:, params:)
super(user: user, repository: column.repository, team: team, column_name: nil)
@column = column
@params = params
end
def call
return self unless valid?
2019-11-11 05:36:17 +08:00
if @column.update(column_attributes)
log_activity(:edit_column_inventory)
else
errors[:repository_column] = @column.errors.messages
end
self
end
2019-11-11 05:36:17 +08:00
private
def column_attributes
@params[:repository_status_items_attributes]&.map do |m|
# assign for new records only
m.merge!(repository_id: @repository.id, created_by_id: @user.id, last_modified_by_id: @user.id) unless m[:id]
end
@params
end
end
end