Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Caio-Antonio committed Jun 16, 2024
2 parents 7ec1e47 + 77feefa commit 9e421b1
Show file tree
Hide file tree
Showing 84 changed files with 858 additions and 1,242 deletions.
72 changes: 0 additions & 72 deletions backend/app/controllers/cargos_controller.rb

This file was deleted.

34 changes: 24 additions & 10 deletions backend/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class UsersController < ApplicationController

# GET /users or /users.json
def index
@users = User.order(:id).all
render json: @users
@users = User.includes(:acesso).order(:id).all
render json: @users.to_json(include: :acesso)
end

# GET /users/1 or /users/1.json
def show; end
def show
render json: @user.to_json(include: :acesso)
end

def login
if User.find_by(matricula: user_params[:matricula])
Expand Down Expand Up @@ -46,13 +48,13 @@ def create
nome = user_params[:nome]
matricula = user_params[:matricula]
email = user_params[:email]
cargoID = user_params[:cargo_id]
@user = User.new(nome:, matricula:, email:, senha: hash, cargo_id: cargoID)
@user = User.new(nome:, matricula:, email:, senha: hash)
@user.build_acesso(acesso_params)

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

# respond_to do |format|
Expand All @@ -70,6 +72,11 @@ def create
def update
set_user
if @user.update(update_params)
if @user.acesso.present?
@user.acesso.update(acesso_params)
else
@user.create_acesso(acesso_params)
end
render json: @user, status: :ok
else
render json: @user.errors, status: :unprocessable_entity
Expand All @@ -93,7 +100,10 @@ def update_password

# DELETE /users/1 or /users/1.json
def destroy
@user.destroy!
set_user
@user.destroy

@user.acesso.destroy if @user.acesso.present?
end

private
Expand All @@ -105,11 +115,15 @@ def set_user

# Only allow a list of trusted parameters through.
def user_params
params.require(:user).permit(:nome, :matricula, :email, :senha, :cargo_id, :token)
params.require(:user).permit(:nome, :matricula, :email, :senha, :token)
end

def acesso_params
params.require(:acesso).permit(:acesso_documents, :acesso_meetings, :acesso_calendar, :acesso_finance, :acesso_admin)
end

def update_params
params.require(:user).permit(:nome, :matricula, :email, :cargo_id)
params.require(:user).permit(:nome, :matricula, :email)
end

def password_params
Expand Down
2 changes: 0 additions & 2 deletions backend/app/helpers/cargos_helper.rb

This file was deleted.

4 changes: 4 additions & 0 deletions backend/app/models/acesso.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Acesso < ApplicationRecord
belongs_to :user
validates :user, presence: true
end
3 changes: 0 additions & 3 deletions backend/app/models/cargo.rb

This file was deleted.

3 changes: 2 additions & 1 deletion backend/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class User < ApplicationRecord
belongs_to :cargo
has_one :acesso, dependent: :destroy
accepts_nested_attributes_for :acesso
has_many :estoques
has_many :eventos
has_many :documentos
Expand Down
17 changes: 0 additions & 17 deletions backend/app/views/documentos/_documento.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions backend/app/views/documentos/_documento.json.jbuilder

This file was deleted.

32 changes: 0 additions & 32 deletions backend/app/views/documentos/_form.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions backend/app/views/documentos/edit.html.erb

This file was deleted.

14 changes: 0 additions & 14 deletions backend/app/views/documentos/index.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion backend/app/views/documentos/index.json.jbuilder

This file was deleted.

9 changes: 0 additions & 9 deletions backend/app/views/documentos/new.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions backend/app/views/documentos/show.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion backend/app/views/documentos/show.json.jbuilder

This file was deleted.

2 changes: 0 additions & 2 deletions backend/app/views/eventos/_evento.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions backend/app/views/eventos/_evento.json.jbuilder

This file was deleted.

17 changes: 0 additions & 17 deletions backend/app/views/eventos/_form.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions backend/app/views/eventos/edit.html.erb

This file was deleted.

14 changes: 0 additions & 14 deletions backend/app/views/eventos/index.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion backend/app/views/eventos/index.json.jbuilder

This file was deleted.

9 changes: 0 additions & 9 deletions backend/app/views/eventos/new.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions backend/app/views/eventos/show.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion backend/app/views/eventos/show.json.jbuilder

This file was deleted.

32 changes: 0 additions & 32 deletions backend/app/views/reuniaos/_form.html.erb

This file was deleted.

Loading

0 comments on commit 9e421b1

Please sign in to comment.