Commit b53085e1 authored by mateus ravedutti's avatar mateus ravedutti

Adjust tables fields

parent 85f18985
......@@ -73,16 +73,18 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def citizen_params
params.require(:citizen).permit(
:birth_date,
:name,
:rg,
:id,
:account_id,
:active,
:address_complement,
:address_number,
:address_street,
:birth_date,
:cep,
:city_id,
:cpf,
:email,
:name,
:neighborhood,
:note,
:pcd,
......@@ -92,7 +94,7 @@ module Api::V1
:photo_file_name,
:photo_file_size,
:photo_update_at,
:account_id
:rg
)
end
end
......
......@@ -72,29 +72,30 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def city_hall_params
params.require(:city_hall).permit(
:city_id,
:id,
:active,
:address_complement,
:address_number,
:address_street,
:block_text,
:cep,
:citizen_access,
:citizen_register,
:name,
:neighborhood,
:previous_notice,
:schedule_period,
:address_complement,
:city_id,
:cep,
:description,
:email,
:logo_content_type,
:logo_file_name,
:logo_file_size,
:logo_updated_at,
:name,
:neighborhood,
:previous_notice,
:phone1,
:phone2,
:support_email,
:schedule_period,
:show_professional,
:support_email,
:url
)
end
......
......@@ -25,7 +25,7 @@ module Api::V1
@dependant = Dependant.new(dependant_params)
if @dependant.save
render json: @dependant, status: :created, location: @dependant
render json: @dependant, status: :created
else
render json: @dependant.errors, status: :unprocessable_entity
end
......@@ -69,8 +69,10 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def dependant_params
params.require(:dependant).permit(
:deactivation,
:active
:id,
:active,
:citizen_id,
:deactivation
)
end
end
......
......@@ -72,10 +72,10 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def occupation_params
params.require(:occupation).permit(
:description,
:name,
:active,
:city_hall_id
:city_hall_id,
:description,
:name
)
end
end
......
......@@ -25,7 +25,7 @@ module Api::V1
@professional = Professional.new(professional_params)
if @professional.save
render json: @professional, status: :created, location: @professional
render json: @professional, status: :created
else
render json: @professional.errors, status: :unprocessable_entity
end
......@@ -68,8 +68,11 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def professional_params
params.require(:professional).permit(
:registration,
:active
:id,
:active,
:account_id,
:occupation_id,
:registration
)
end
end
......
......@@ -71,18 +71,19 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def schedule_params
params.require(:schedule).permit(
:shift_id,
:situation_id,
:service_place_id,
:id,
:account_id,
:citizen_ajax_read,
:note,
:professional_ajax_read,
:reminder_read,
:reminder_email_sent,
:reminder_time,
:service_start_time,
:service_end_time,
:note,
:reminder_email_sent,
:reminder_time
:service_place_id,
:shift_id,
:situation_id
)
end
end
......
......@@ -74,11 +74,12 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def sector_params
params.require(:sector).permit(
:active,
:city_hall_id,
:id,
:absence_max,
:active,
:blocking_days,
:cancel_limit,
:city_hall_id,
:description,
:name,
:schedules_by_sector
......
......@@ -72,14 +72,16 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def service_place_params
params.require(:service_place).permit(
:id,
:active,
:address_complement,
:address_number,
:address_street,
:name,
:neighborhood,
:address_complement,
:cep,
:city_hall_id,
:email,
:name,
:neighborhood,
:phone1,
:phone2,
:url
......
......@@ -74,9 +74,10 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def service_type_params
params.require(:service_type).permit(
:id,
:active,
:sector_id,
:description
:description,
:sector_id
)
end
end
......
......@@ -71,15 +71,16 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def shift_params
params.require(:shift).permit(
:service_place_id,
:service_type_id,
:id,
:execution_start_time,
:execution_end_time,
:next_shift_id,
:notes,
:professional_performer_id,
:professional_responsible_id,
:execution_start_time,
:execution_end_time,
:service_amount,
:notes
:service_place_id,
:service_type_id
)
end
end
......
......@@ -71,11 +71,12 @@ module Api::V1
# Only allow a trusted parameter "white list" through.
def solicitation_params
params.require(:solicitation).permit(
:id,
:cep,
:city_id,
:name,
:cpf,
:email,
:cep,
:name,
:phone,
:sent
)
......
......@@ -38,16 +38,16 @@ class Citizen < ApplicationRecord
# @return list of citizen's columns
def self.keys
return [
:birth_date,
:name,
:rg,
:active,
:address_complement,
:address_number,
:address_street,
:birth_date,
:cep,
:city_id,
:cpf,
:email,
:name,
:neighborhood,
:note,
:pcd,
......@@ -57,7 +57,7 @@ class Citizen < ApplicationRecord
:photo_file_name,
:photo_file_size,
:photo_update_at,
:active
:rg
]
end
......
......@@ -4,14 +4,6 @@ class Dependant < ApplicationRecord
belongs_to :citizen
has_many :blocks
# @return list of dependant's columns
def self.keys
return [
:active,
:deactivated
]
end
# @return all active dependants
def self.all_active
Dependant.where(active: true)
......
......@@ -10,14 +10,6 @@ class Professional < ApplicationRecord
# Validations #
validates_presence_of :occupation_id, :account_id
# @return list of professional's columns
def self.keys
return [
:active,
:registration
]
end
# @return all active professionals
def self.all_active
Professional.where(active: true)
......
......@@ -12,22 +12,4 @@ class Schedule < ApplicationRecord
:reminder_read
:service_start_time
:service_end_time
# @return list of schedule's columns
def self.keys
return [
:shift_id,
:situation_id,
:service_place_id,
:account_id,
:citizen_ajax_read,
:professional_ajax_read,
:reminder_read,
:service_start_time,
:service_end_time,
:note,
:reminder_email_sent,
:remainder_time
]
end
end
......@@ -21,19 +21,4 @@ class Shift < ApplicationRecord
validates_presence_of :execution_start_time
:execution_end_time
:service_amount
# @return list of shift's columns
def self.keys
return [
:service_place_id,
:service_type_id,
:next_shift_id,
:professional_performer_id,
:professional_responsible_id,
:execution_start_time,
:execution_end_time,
:service_amount,
:notes
]
end
end
......@@ -5,11 +5,4 @@ class Situation < ApplicationRecord
# Validations #
validates_presence_of :description
# @return list of shift's columns
def self.keys
return [
:description
]
end
end
class AccountSerializer < ActiveModel::Serializer
attributes :id, :uid, :provider
has_one :citizen
#has_one :citizen
end
class CitizenSerializer < ActiveModel::Serializer
attributes :id, :birth_date, :name, :rg,
:address_complement, :address_number,
:address_street, :cep, :city_id, :cpf,
:email, :neighborhood, :note, :pcd,
:phone1, :phone2, :photo_content_type,
:photo_file_name, :photo_file_size,
:photo_update_at, :active
attributes :id,
:active,
:address_complement,
:address_number,
:address_street,
:birth_date,
:cep,
:city_id,
:cpf,
:email,
:name,
:neighborhood,
:note,
:pcd,
:phone1,
:phone2,
:photo_content_type,
:photo_file_name,
:photo_file_size,
:photo_update_at,
:rg
belongs_to :account
end
class CityHallSerializer < ActiveModel::Serializer
attributes :id, :city_id, :active, :address_number,
:address_street, :block_text, :cep,
:citizen_access, :citizen_register,
:name, :neighborhood, :previous_notice,
:schedule_period, :address_complement,
:description, :email, :logo_content_type,
:logo_file_name, :logo_file_size,
:logo_updated_at, :phone1, :phone2,
:support_email, :show_professional, :url
attributes :id,
:active,
:address_complement,
:address_number,
:address_street,
:block_text,
:citizen_access,
:citizen_register,
:cep,
:description,
:email,
:logo_content_type,
:logo_file_name,
:logo_file_size,
:logo_updated_at,
:name,
:neighborhood,
:previous_notice,
:phone1,
:phone2,
:schedule_period,
:show_professional,
:support_email,
:url
belongs_to :city
end
class DependantSerializer < ActiveModel::Serializer
attributes :id, :active, :deactivated
attributes :id,
:active,
:deactivated
belongs_to :citizen
end
class OccupationSerializer < ActiveModel::Serializer
attributes :id, :description, :name, :active
attributes :id,
:active,
:description,
:name
has_one :city_hall
end
class ProfessionalSerializer < ActiveModel::Serializer
ActiveModelSerializers.config.default_includes = '**'
attributes :id, :registration, :active
attributes :id,
:active,
:registration
has_one :citizen, through: :account
has_one :occupation
end
class ScheduleSerializer < ActiveModel::Serializer
belongs_to :situation
belongs_to :shift
attributes :id,
:account_id,
:citizen_ajax_read,
:note,
:professional_ajax_read,
:reminder_email_sent,
:reminder_read,
:remainder_time,
:service_start_time,
:service_end_time
belongs_to :service_place
attributes :id, :citizen_ajax_read, :professional_ajax_read, :reminder_read,
:service_start_time, :service_end_time, :note, :reminder_email_sent,
:remainder_time, :account_id
belongs_to :shift
belongs_to :situation
end
class SectorSerializer < ActiveModel::Serializer
attributes :id,
:absence_max,
:active,
:blocking_days,
:cancel_limit,
:description,
:name,
:schedules_by_sector
belongs_to :city_hall
attributes :id, :name, :absence_max, :blocking_days, :cancel_limit, :description, :name
end
class ServicePlaceSerializer < ActiveModel::Serializer
attributes :id, :active, :address_number, :address_street,
:name, :neighborhood, :address_complement, :cep,
:email, :phone1, :phone2, :url
attributes :id,
:active,
:address_complement,
:address_number,
:address_street,
:cep,
:email,
:name,
:neighborhood,
:phone1,
:phone2,
:url
belongs_to :city_hall
end
class ServiceTypeSerializer < ActiveModel::Serializer
attributes :id,
:active,
:description
belongs_to :sector
attributes :id, :active, :description
end
class ShiftSerializer < ActiveModel::Serializer
attributes :id,
:execution_start_time,
:execution_end_time,
:notes,
:service_amount
belongs_to :service_place
belongs_to :service_type
has_one :shift, :foreign_key => :next_shift_id, :class_name => "Shift"
......@@ -6,6 +12,4 @@ class ShiftSerializer < ActiveModel::Serializer
:class_name => "Professional"
belongs_to :professional_2, :foreign_key => :professional_performer_id,
:class_name => "Professional"
attributes :id, :execution_start_time, :execution_end_time,
:service_amount, :notes
end
class SolicitationSerializer < ActiveModel::Serializer
attributes :id, :name, :cpf, :email, :cep, :phone, :sent
attributes :id,
:cep,
:cpf,
:email,
:name,
:phone,
:sent
has_one :city
end
......@@ -28,13 +28,10 @@ class Api::V1::DependantsControllerTest < ActionDispatch::IntegrationTest
password: "123mudar",
password_confirmation: "123mudar")
@dependant = Dependant.new(active: true)
@account.save!
@citizen.account_id = @account.id
@citizen.save!
@dependant.citizen_id = @citizen.id
@dependant.save!
@auth_headers = @account.create_new_auth_token
......@@ -43,10 +40,15 @@ class Api::V1::DependantsControllerTest < ActionDispatch::IntegrationTest
@expiry = @auth_headers['expiry']
end
describe "Successful request to show dependant" do
describe "Successful request to create dependant" do
before do
get '/v1/dependants/' + @dependant.id.to_s, params: {},
headers: @auth_headers
@number_of_dependants = Dependant.count
post '/v1/dependants', params: {dependant: {
citizen_id: @citizen.id,
active: true
}}, headers: @auth_headers
@body = JSON.parse(response.body)
@resp_token = response.headers['access-token']
......@@ -56,55 +58,87 @@ class Api::V1::DependantsControllerTest < ActionDispatch::IntegrationTest
end
it "should be successful" do
assert_equal 200, response.status
assert_equal 201, response.status
end
it "should correspond to the current account" do
assert_equal @body["id"], @controller.current_account.citizen.dependant.id
it "should correspond to the created dependant" do
assert_equal @body["citizen_id"], @citizen_id
end
it "should correspond to the dependant in the database" do
assert_equal @body["citizen"]["cpf"], Dependant.find(@dependant.id).citizen.cpf
it "should create a dependant" do
assert_equal @number_of_dependants+1, Dependant.count
end
end
describe "Successful request to delete dependant" do
before do
delete '/v1/dependants/' + @dependant.id.to_s, params: {},
headers: @auth_headers
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
@resp_uid = response.headers['uid']
end
it "should be successful" do
assert_equal 204, response.status
describe "Successful request to show dependant" do
before do
@dependant = Dependant.where(citizen_id: @citizen.id).first
get '/v1/dependants/' + @dependant.id.to_s, params: {},
headers: @auth_headers
@body = JSON.parse(response.body)
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
@resp_uid = response.headers['uid']
end
it "should be successful" do
assert_equal 200, response.status
end
it "should correspond to the current account" do
assert_equal @body["id"], @controller.current_account.citizen.dependant.id
end
it "should correspond to the dependant in the database" do
assert_equal @body["citizen"]["cpf"], Dependant.find(@dependant.id).citizen.cpf
end
end
it "should have been deleted" do
assert_equal Dependant.where(id: @dependant.id).first.active, false
describe "Successful request to delete dependant" do
before do
@dependant = Dependant.where(citizen_id: @citizen.id).first
delete '/v1/dependants/' + @dependant.id.to_s, params: {},
headers: @auth_headers
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
@resp_uid = response.headers['uid']
end
it "should be successful" do
assert_equal 204, response.status
end
it "should have been deleted" do
assert_equal Dependant.where(id: @dependant.id).first.active, false
end
end
end
describe "Successful request to update dependant" do
before do
put '/v1/dependants/' + @dependant.id.to_s,
params: {dependant: { active: false }}, headers: @auth_headers
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
@resp_uid = response.headers['uid']
end
describe "Successful request to update dependant" do
before do
it "should be successful" do
assert_equal 200, response.status
end
@dependant = Dependant.where(citizen_id: @citizen.id).first
put '/v1/dependants/' + @dependant.id.to_s,
params: {dependant: { active: false }}, headers: @auth_headers
@resp_token = response.headers['access-token']
@resp_client_id = response.headers['client']
@resp_expiry = response.headers['expiry']
@resp_uid = response.headers['uid']
end
it "should be successful" do
assert_equal 200, response.status
end
test "registration number should have been changed" do
@dependant = Citizen.where(cpf: @citizen.cpf).first.dependant
assert_equal false, @dependant.active
test "registration number should have been changed" do
@dependant = Citizen.where(cpf: @citizen.cpf).first.dependant
assert_equal false, @dependant.active
end
end
end
end
......