chore: Get all notification API improvments (#8549)

Co-authored-by: Sojan Jose <sojan@chatwoot.com>
This commit is contained in:
Muhsin Keloth
2024-01-17 09:02:18 +05:30
committed by GitHub
parent e67f8824d9
commit 818424259f
10 changed files with 176 additions and 31 deletions

View File

@@ -7,9 +7,9 @@ class Api::V1::Accounts::NotificationsController < Api::V1::Accounts::BaseContro
before_action :set_current_page, only: [:index]
def index
@unread_count = current_user.notifications.where(account_id: current_account.id, read_at: nil).count
@count = notifications.count
@notifications = notifications.page(@current_page).per(RESULTS_PER_PAGE)
@unread_count = notification_finder.unread_count
@notifications = notification_finder.perform
@count = @notifications.count
end
def read_all
@@ -35,7 +35,7 @@ class Api::V1::Accounts::NotificationsController < Api::V1::Accounts::BaseContro
end
def unread_count
@unread_count = current_user.notifications.where(account_id: current_account.id, read_at: nil).count
@unread_count = notification_finder.unread_count
render json: @unread_count
end
@@ -61,7 +61,7 @@ class Api::V1::Accounts::NotificationsController < Api::V1::Accounts::BaseContro
@current_page = params[:page] || 1
end
def notifications
@notifications ||= current_user.notifications.where(account_id: current_account.id)
def notification_finder
@notification_finder ||= NotificationFinder.new(Current.user, Current.account, params)
end
end