2019-10-16 19:26:53 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RepositoryColumns
|
2019-10-16 21:07:46 +08:00
|
|
|
class UpdateColumnService < RepositoryColumns::ColumnService
|
2019-10-16 19:26:53 +08:00
|
|
|
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)
|
2019-10-16 19:26:53 +08:00
|
|
|
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
|
2020-05-15 23:46:59 +08:00
|
|
|
m.merge!(created_by_id: @user.id, last_modified_by_id: @user.id) unless m[:id]
|
2019-11-11 05:36:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@params
|
|
|
|
end
|
2019-10-16 19:26:53 +08:00
|
|
|
end
|
|
|
|
end
|