Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/graphql/resolvers/create_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Resolvers::CreateUser < Resolvers::MutationFunction
argument :email, !types.String
argument :password, !types.String
argument :password_confirmation, !types.String
argument :role, !types.String
argument :role, !types[types.String]
argument :profile_picture_b64, as: :attachment do
type types.String
description 'The base64 encoded version of the profile picture.'
Expand Down Expand Up @@ -34,9 +34,11 @@ def call(_obj, args, ctx)
created_at: Time.now,
profile_picture: args["attachment"] || nil,
)
role = Role.find_by(title: args["role"])
if args["role"] and role != nil and !@new_user.roles.include?(role)
@new_user.roles << role
args["role"].each do |role|
roley = Role.find_by(title: role)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a naming convention for variables in this case, and they're usually named with an @ before the name. In this instance, the name would be @role

if roley and role != nil and !@new_user.roles.include?(roley)
@new_user.roles << roley
end
end
Authentication::generate_new_header(ctx) if @new_user.save!
return @new_user
Expand Down
11 changes: 7 additions & 4 deletions app/graphql/resolvers/update_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Resolvers::UpdateUser < Resolvers::MutationFunction
argument :first_name, types.String
argument :last_name, types.String
argument :email, types.String
argument :role, types.String
argument :role, !types[types.String]
argument :profile_picture_b64, as: :attachment do
type types.String
description 'The base64 encoded bersion of the attatchment to upload.'
Expand Down Expand Up @@ -35,9 +35,12 @@ def call(_obj, args, ctx)
save = "" if save =~ /\d/ else save
@user.slug = args["first_name"].downcase + "-" + args["last_name"].downcase + save
end
role = Role.find_by(title: args["role"])
if args["role"] and role != nil and !@user.roles.include?(role)
@user.roles << role
@user.roles.clear
args["role"].each do |role|
roley = Role.find_by(title: role)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

if roley and role != nil
@user.roles << roley
end
end
Authentication::generate_new_header(ctx) if @user.save!
end
Expand Down