Sha256: 479d1c8f6262f3de7c37dd5d1e101529ff09890f4cba2af00f8afec1aed65d1e

Contents?: true

Size: 1019 Bytes

Versions: 4

Compression:

Stored size: 1019 Bytes

Contents

module Api
  class WebhooksController < Api::BaseController
    def update_user_callback
      return render_not_found unless user

      user.update(user_params)
      InfinumId::AfterUserUpdate.call(user, params[:user])

      render json: { user: 'updated' }
    end

    def create_user_callback
      return render_already_exists if user

      user = User.create(user_params.merge(provider: params[:provider]))
      InfinumId::AfterUserCreate.call(user, params[:user])

      render json: { user: 'created' }
    end

    private

    def user_params
      params.require(:user).permit(
        :uid, :email, :first_name, :last_name, :slack_username,
        :time_zone, :deactivated_at, :avatar_url
      )
    end

    def user
      @user ||= User.find_by(uid: user_params[:uid])
    end

    def render_not_found
      render json: { user: 'not found' }, status: :not_found
    end

    def render_already_exists
      render json: { user: 'already exists' }, status: :unprocessable_entity
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
infinum_id-1.3.1 app/controllers/api/webhooks_controller.rb
infinum_id-1.3.0 app/controllers/api/webhooks_controller.rb
infinum_id-1.2.0 app/controllers/api/webhooks_controller.rb
infinum_id-1.1.0 app/controllers/api/webhooks_controller.rb