Update blueprint for availability endpoints
This commit is contained in:
parent
153d36be5a
commit
e91e1664a6
2 changed files with 8 additions and 8 deletions
|
|
@ -3,12 +3,12 @@
|
|||
module Api
|
||||
module V1
|
||||
class EmptyBlueprint < Blueprinter::Base
|
||||
field :email_available, if: ->(_field_name, _empty, options) { options.key?(:email) } do |_, options|
|
||||
User.where('email = ?', options[:email]).count.zero?
|
||||
end
|
||||
|
||||
field :username_available, if: ->(_field_name, _empty, options) { options.key?(:username) } do |_, options|
|
||||
User.where('username = ?', options[:username]).count.zero?
|
||||
field :available, if: ->(_field_name, _empty, options) { options.key?(:availability) } do |_, options|
|
||||
if options.key?(:email)
|
||||
User.where('email = ?', options[:email]).count.zero?
|
||||
elsif options.key?(:username)
|
||||
User.where('username = ?', options[:username]).count.zero?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -69,11 +69,11 @@ module Api
|
|||
end
|
||||
|
||||
def check_email
|
||||
render json: EmptyBlueprint.render_as_json(nil, email: params[:email])
|
||||
render json: EmptyBlueprint.render_as_json(nil, email: params[:email], availability: true)
|
||||
end
|
||||
|
||||
def check_username
|
||||
render json: EmptyBlueprint.render_as_json(nil, username: params[:username])
|
||||
render json: EmptyBlueprint.render_as_json(nil, username: params[:username], availability: true)
|
||||
end
|
||||
|
||||
def destroy; end
|
||||
|
|
|
|||
Loading…
Reference in a new issue