Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
Add Comment
Please, Sign In to add comment