Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajusta erro na query em horario critico #147

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion app/controllers/visitor_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index

@result = []
params.permit(:full_name, :visit_date, :identity_number).each do |key, value|
key = 'created_at' if key == 'visit_date'
key = 'database_datetime' if key == 'visit_date'
@result << find_visitor_entries(key, value) if value.present?
end

Expand Down
8 changes: 8 additions & 0 deletions app/models/visitor_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ class VisitorEntry < ApplicationRecord
validates :identity_number, length: { in: 5..10 }
validates :identity_number,
format: { with: ID_REGEX, message: I18n.t('alerts.visitor_entry.only_numbers_and_letters') }

before_save :set_database_datetime

private

def set_database_datetime
self.database_datetime ||= (DateTime.now + Time.zone.utc_offset.seconds)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDatabaseDatetimeToVisitorEntry < ActiveRecord::Migration[7.1]
def change
add_column :visitor_entries, :database_datetime, :datetime, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 41 additions & 30 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,15 @@
rules: 'Acompanhamento de adulto obrigatório'
)

visitor_1 = Visitor.create!(
Visitor.create!(
condo: resident1.residence.condo,
resident: resident1,
visit_date: Time.zone.today,
full_name: 'João da Silva Ferreira',
identity_number: '1456987',
category: :visitor
)
visitor_2 = Visitor.create!(
Visitor.create!(
condo: resident1.residence.condo,
resident: resident1,
visit_date: Time.zone.today,
Expand All @@ -741,15 +741,15 @@
category: :employee,
recurrence: :working_days
)
visitor_3 = Visitor.create!(
Visitor.create!(
condo: resident2.residence.condo,
resident: resident2,
visit_date: Time.zone.today,
full_name: 'Pedro Souza Santos',
identity_number: '3214567',
category: :visitor
)
visitor_4 = Visitor.create!(
Visitor.create!(
condo: resident2.residence.condo,
resident: resident2,
visit_date: 1.day.from_now.to_date,
Expand All @@ -758,7 +758,7 @@
category: :employee,
recurrence: :monthly
)
visitor_5 = Visitor.create!(
Visitor.create!(
condo: resident3.residence.condo,
resident: resident3,
visit_date: 1.day.from_now.to_date,
Expand All @@ -767,23 +767,23 @@
category: :employee,
recurrence: :biweekly
)
visitor_6 = Visitor.create!(
Visitor.create!(
condo: resident3.residence.condo,
resident: resident3,
visit_date: Time.zone.today,
full_name: 'Beatriz Oliveira Costa',
identity_number: '6901234',
category: :visitor
)
visitor_7 = Visitor.create!(
Visitor.create!(
condo: resident3.residence.condo,
resident: resident3,
visit_date: 2.days.from_now.to_date,
full_name: 'Bruno Souza Nunes',
identity_number: '7890123',
category: :visitor
)
visitor_8 = Visitor.create!(
Visitor.create!(
condo: resident4.residence.condo,
resident: resident4,
visit_date: Time.zone.today,
Expand All @@ -792,15 +792,15 @@
category: :employee,
recurrence: :bimonthly
)
visitor_9 = Visitor.create!(
Visitor.create!(
condo: resident4.residence.condo,
resident: resident4,
visit_date: 1.day.from_now,
full_name: 'Diego Silva Lopes',
identity_number: '9654321',
category: :visitor
)
visitor_10 = Visitor.create!(
Visitor.create!(
condo: resident5.residence.condo,
resident: resident5,
visit_date: Time.zone.today,
Expand All @@ -810,62 +810,73 @@
recurrence: :semiannual
)

visitor_entry1 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo1,
full_name: 'Maria Fernandes',
identity_number: '1234567',
unit: tower1.floors[0].units[0]
unit: tower1.floors[0].units[0],
database_datetime: 1.day.ago
)
visitor_entry2 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo1,
full_name: 'João Pereira',
identity_number: '2345678',
unit: tower1.floors[0].units[1]
unit: tower1.floors[0].units[1],
database_datetime: 3.days.ago.to_datetime

)
visitor_entry3 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo1,
full_name: 'Ana Souza',
identity_number: '3456789',
unit: tower1.floors[1].units[3]
unit: tower1.floors[1].units[3],
database_datetime: 14.days.ago.to_datetime
)
visitor_entry4 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo1,
full_name: 'Carlos Lima',
identity_number: '4567890'
identity_number: '4567890',
database_datetime: 30.days.ago.to_datetime
)
visitor_entry5 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo1,
full_name: 'Patricia Mendes',
identity_number: '5678901'
identity_number: '5678901',
database_datetime: 1.day.ago.to_datetime
)
visitor_entry6 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo1,
full_name: 'Lucas Alves',
identity_number: '6789012',
unit: tower1.floors[2].units[0]
unit: tower1.floors[2].units[0],
database_datetime: 2.days.ago.to_datetime
)
visitor_entry7 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo1,
full_name: 'Mariana Costa',
identity_number: '7890123',
unit: tower2.floors[2].units[0]
unit: tower2.floors[2].units[0],
database_datetime: 3.days.ago.to_datetime
)
visitor_entry8 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo1,
full_name: 'Fernando Gomes',
identity_number: '8901234',
unit: tower2.floors[0].units[0]
unit: tower2.floors[0].units[0],
database_datetime: 4.days.ago.to_datetime
)
visitor_entry9 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo2,
full_name: 'Juliana Oliveira',
identity_number: '9012345',
unit: tower3.floors[0].units[0]
unit: tower3.floors[0].units[0],
database_datetime: 1.days.ago.to_datetime
)
visitor_entry10 = VisitorEntry.create!(
VisitorEntry.create!(
condo: condo2,
full_name: 'Gustavo Ferreira',
identity_number: '0123456'
identity_number: '0123456',
database_datetime: 1.days.ago.to_datetime
)
Announcement.create!(
title: 'Reunião de condomínio',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
end
end

context 'and searchs' do
context 'and searches' do
it 'with visitor name filter' do
resident = create :resident, :with_residence
first_visitor = create :visitor, resident:, full_name: 'João Ferreira', identity_number: 145_364
Expand Down
8 changes: 4 additions & 4 deletions spec/system/visitor_entry/manager_see_visitor_entries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@
it 'with visit date filter' do
manager = create :manager
condo = create :condo
travel_to '04/07/2024' do
travel_to Time.zone.local(2024, 7, 4, 22, 0) do
create :visitor_entry, condo:, full_name: 'Nome Visitante Ontem'
end

travel_to '05/07/2024' do
travel_to Time.zone.local(2024, 7, 5, 22, 1) do
create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante'
end

travel_to '05/07/2024 00:30' do
travel_to Time.zone.local(2024, 7, 5, 22, 2) do
create :visitor_entry, condo:, full_name: 'Nome Último Visitante'

login_as manager, scope: :manager
Expand Down Expand Up @@ -136,7 +136,7 @@
end

it 'with all filters' do
travel_to '05/07/2024' do
travel_to Time.zone.local(2024, 7, 5, 22, 1) do
manager = create :manager
condo = create :condo
create :visitor_entry, condo:, full_name: 'Nome Primeiro Visitante', identity_number: '145697'
Expand Down
Loading