Guest User

Untitled

a guest
Jan 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. module ProjectApp
  4. module Commands
  5. module UsersProject
  6. class Upsert
  7. include Import["interactors.users_project_repository"]
  8.  
  9. def call(params)
  10. @params = params
  11.  
  12. users_project_repository
  13. .users_projects
  14. .dataset
  15. .insert_conflict(opts)
  16. .insert(params)
  17. end
  18.  
  19. private
  20.  
  21. attr_reader :params
  22.  
  23. def opts
  24. {
  25. target: [:project_id, :user_id],
  26. update: {
  27. teams: Sequel.pg_array(processed_teams),
  28. }
  29. }
  30. end
  31.  
  32. def processed_teams
  33. existed_teams = users_project_repository
  34. .find_by(project_id: params[:project_id], user_id: params[:user_id])
  35. .teams
  36.  
  37. existed_teams.push(*params[:teams]).uniq
  38. end
  39. end
  40. end
  41. end
  42. end
Add Comment
Please, Sign In to add comment