2019-10-09 20:09:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RepositoryColumns
|
2019-10-16 21:07:46 +08:00
|
|
|
class CreateColumnService < RepositoryColumns::ColumnService
|
|
|
|
def initialize(user:, repository:, params:, team:, column_type:)
|
2019-10-16 19:26:53 +08:00
|
|
|
super(user: user, repository: repository, team: team, column_name: params[:name])
|
2019-10-16 21:07:46 +08:00
|
|
|
@column_type = column_type
|
2019-10-16 19:26:53 +08:00
|
|
|
@params = params
|
2019-10-09 20:09:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
|
|
|
return self unless valid?
|
|
|
|
|
2019-10-16 21:07:46 +08:00
|
|
|
@column = RepositoryColumn.new(column_attributes)
|
2019-10-09 20:09:27 +08:00
|
|
|
|
2019-10-16 19:26:53 +08:00
|
|
|
if @column.save
|
|
|
|
log_activity(:create_column_inventory)
|
|
|
|
else
|
|
|
|
errors[:repository_column] = @column.errors.messages
|
2019-10-09 20:09:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-10-16 21:07:46 +08:00
|
|
|
def column_attributes
|
|
|
|
@params[:repository_status_items_attributes]&.map do |m|
|
2020-04-09 23:11:58 +08:00
|
|
|
m.merge!(created_by_id: @user.id, last_modified_by_id: @user.id)
|
2019-10-16 21:07:46 +08:00
|
|
|
end
|
|
|
|
|
2019-10-16 19:26:53 +08:00
|
|
|
@params[:repository_list_items_attributes]&.map do |m|
|
2020-04-09 23:11:58 +08:00
|
|
|
m.merge!(created_by_id: @user.id, last_modified_by_id: @user.id)
|
2019-10-16 19:26:53 +08:00
|
|
|
end
|
2019-10-16 21:07:46 +08:00
|
|
|
|
2019-12-09 20:38:40 +08:00
|
|
|
@params[:repository_checklist_items_attributes]&.map do |m|
|
2020-04-09 23:11:58 +08:00
|
|
|
m.merge!(created_by_id: @user.id, last_modified_by_id: @user.id)
|
2019-12-06 20:18:35 +08:00
|
|
|
end
|
|
|
|
|
2022-01-18 20:17:05 +08:00
|
|
|
@params[:repository_stock_unit_items_attributes]&.map do |m|
|
|
|
|
m.merge!(created_by_id: @user.id, last_modified_by_id: @user.id)
|
|
|
|
end
|
|
|
|
|
2019-10-16 21:07:46 +08:00
|
|
|
@params.merge(repository_id: @repository.id, created_by_id: @user.id, data_type: @column_type)
|
2019-10-09 20:09:27 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|