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::AfterUserUpdate.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