Class: Motor::NotificationsController

Inherits:
ApiBaseController show all
Defined in:
app/controllers/motor/notifications_controller.rb

Instance Method Summary collapse

Methods included from CurrentAbility

#current_ability

Methods included from CurrentUserMethod

#current_user

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/motor/notifications_controller.rb', line 9

def index
  @notifications =
    Motor::ApiQuery.call(@notifications.where(recipient: current_user).order(created_at: :desc), params)

  render json: {
    data: Motor::ApiQuery::BuildJson.call(@notifications, params, current_ability),
    meta: Motor::ApiQuery::BuildMeta.call(@notifications, params)
  }
end

#updateObject



19
20
21
22
23
24
25
# File 'app/controllers/motor/notifications_controller.rb', line 19

def update
  @notification.update!(notification_params)

  Motor::NotificationsChannel.broadcast_to(current_user, ['update', @notification.as_json(include: i[record])])

  render json: { data: Motor::ApiQuery::BuildJson.call(@notification, params, current_ability) }
end