class School::HelpNotificationsController < ApplicationController
  def index
    render_success :ok, json: help_notifications
  end

  def create
    dismissed = current_user.dismissed_help_notifications
      .build(notification_id: params[:notification_id])
    if dismissed.save
      render_success :ok
    else
      render_error :unprocessable_entity
    end
  end

  private
    def help_notifications
      Help::Notification
        .where(active: true)
        .where('expiration >= ?', Time.zone.now)
        .where.not(id: dismissed_notification_ids)
    end

    def dismissed_notification_ids
      current_user.dismissed_help_notifications.pluck(:notification_id)
    end
end
