summaryrefslogtreecommitdiff
path: root/app/models/diff_note_position.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/diff_note_position.rb')
-rw-r--r--app/models/diff_note_position.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/models/diff_note_position.rb b/app/models/diff_note_position.rb
index 78e4fbc49eb..716a56c6430 100644
--- a/app/models/diff_note_position.rb
+++ b/app/models/diff_note_position.rb
@@ -28,9 +28,20 @@ class DiffNotePosition < ApplicationRecord
end
def position=(position)
+ assign_attributes(self.class.position_to_attrs(position))
+ end
+
+ def self.create_or_update_for(note, params)
+ attrs = position_to_attrs(params[:position])
+ attrs.merge!(params.slice(:diff_type, :line_code))
+ attrs[:note_id] = note.id
+
+ upsert(attrs, unique_by: [:note_id, :diff_type])
+ end
+
+ def self.position_to_attrs(position)
position_attrs = position.to_h
position_attrs[:diff_content_type] = position_attrs.delete(:position_type)
-
- assign_attributes(position_attrs)
+ position_attrs
end
end