docbrown/app/controllers/push_notification_subscriptions_controller.rb
Anna Buianova 0ecb937875 Added rubocop-rails (#3059)
* Added rubocop-rails

* Update rubocop version in the CodeClimate config
2019-06-06 09:47:57 -04:00

19 lines
623 B
Ruby

class PushNotificationSubscriptionsController < ApplicationController
def create
@subscription = PushNotificationSubscription.where(endpoint: pns_params[:endpoint]).
first_or_create(
auth_key: pns_params[:keys][:auth],
p256dh_key: pns_params[:keys][:p256dh],
endpoint: pns_params[:endpoint],
user_id: current_user.id,
notification_type: "browser",
)
render json: { status: "success", endpoint: @subscription.endpoint }, status: :created
end
private
def pns_params
params.require(:subscription).permit({ keys: %i[auth p256dh] }, :endpoint)
end
end