2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-14 22:27:53 -04:00
|
|
|
class NoteVersion < ApplicationRecord
|
2019-06-02 10:49:38 -04:00
|
|
|
user_status_counter :note_count, foreign_key: :updater_id
|
|
|
|
belongs_to_updater
|
2018-05-10 14:18:02 -04:00
|
|
|
scope :for_user, ->(user_id) {where("updater_id = ?", user_id)}
|
2013-01-10 17:45:52 -05:00
|
|
|
|
|
|
|
def self.search(params)
|
2018-01-13 13:01:30 -05:00
|
|
|
q = super
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2023-08-03 16:01:53 -04:00
|
|
|
q = q.where_user(:updater_id, :updater, params)
|
2023-02-05 14:48:56 -05:00
|
|
|
|
2013-01-10 17:45:52 -05:00
|
|
|
if params[:post_id]
|
2017-05-14 13:38:39 -04:00
|
|
|
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
|
2013-01-10 17:45:52 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2013-01-11 17:13:55 -05:00
|
|
|
if params[:note_id]
|
2017-05-14 13:38:39 -04:00
|
|
|
q = q.where(note_id: params[:note_id].split(",").map(&:to_i))
|
2013-01-11 17:13:55 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2018-05-03 16:29:43 -04:00
|
|
|
q = q.attribute_matches(:is_active, params[:is_active])
|
2018-08-31 20:23:25 -04:00
|
|
|
q = q.attribute_matches(:body, params[:body_matches])
|
2018-05-03 16:29:43 -04:00
|
|
|
|
2021-10-30 13:46:55 -04:00
|
|
|
if params[:ip_addr].present?
|
|
|
|
q = q.where("updater_ip_addr <<= ?", params[:ip_addr])
|
|
|
|
end
|
|
|
|
|
2023-07-07 08:32:57 -04:00
|
|
|
q.apply_basic_order(params)
|
2013-01-10 17:45:52 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2015-04-15 11:29:15 -04:00
|
|
|
def previous
|
2015-05-16 12:11:27 -04:00
|
|
|
NoteVersion.where("note_id = ? and updated_at < ?", note_id, updated_at).order("updated_at desc").first
|
2015-04-15 11:29:15 -04:00
|
|
|
end
|
2010-02-24 15:40:55 -05:00
|
|
|
end
|