summaryrefslogtreecommitdiff
path: root/app/services/notes/update_service.rb
blob: 4b4f383abf2f0a490cd4aef90da78ae82d618f9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Notes
  class UpdateService < BaseService
    def execute(note)
      return note unless note.editable?

      old_mentioned_users = note.mentioned_users.to_a

      note.assign_attributes(params)
      params.merge!(last_edited_at: Time.now, last_edited_by: current_user) if note.note_changed?

      note.update_attributes(params.merge(updated_by: current_user))

      note.create_new_cross_references!(current_user)

      if note.previous_changes.include?('note')
        TodoService.new.update_note(note, current_user, old_mentioned_users)
      end

      note
    end
  end
end