Skip to content

Commit

Permalink
allow to create user in the users controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Jan 22, 2024
1 parent 6abbee8 commit 3402c04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def show
# This will use app/views/users/show.json.jbuilder
end

def create
@user = User.new(user_params)

if @user.save
render :show, status: :created, location: @user
else
render json: @user.errors, status: :unprocessable_entity
end
end

def update
ApplicationRecord.transaction do
@user.salaries.destroy_all
Expand Down
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class User < ApplicationRecord
extend FriendlyId
friendly_id :name, use: :slugged

validates :email, presence: true, uniqueness: true,
format: {
validates :email, presence: true, uniqueness: true
validates :email, format: {
with: /\A[\w+\-.]+@#{ENV.fetch('VALID_USER_DOMAIN', nil)}\z/i,
message: "must be a #{ENV.fetch('VALID_USER_DOMAIN', nil)} account"
}
}, if: :internal?

validates :google_id, presence: true, uniqueness: true, if: :internal?
validates :google_id, absence: true, unless: :internal?
Expand Down

0 comments on commit 3402c04

Please sign in to comment.