Created
January 9, 2018 13:58
-
-
Save myf9000/dd31a9b43c5ec15352af78957ffeec31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module ProjectApp | |
module Commands | |
module UsersProject | |
class Upsert | |
include Import["interactors.users_project_repository"] | |
def call(params) | |
@params = params | |
users_project_repository | |
.users_projects | |
.dataset | |
.insert_conflict(opts) | |
.insert(params) | |
end | |
private | |
attr_reader :params | |
def opts | |
{ | |
target: [:project_id, :user_id], | |
update: { | |
teams: Sequel.pg_array(processed_teams), | |
} | |
} | |
end | |
def processed_teams | |
existed_teams = users_project_repository | |
.find_by(project_id: params[:project_id], user_id: params[:user_id]) | |
.teams | |
existed_teams.push(*params[:teams]).uniq | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment