Skip to content

Commit

Permalink
Move aggregating after a facility review is created to the facility r…
Browse files Browse the repository at this point in the history
…eview model, instead of controller - now that we only make one review at a time.
  • Loading branch information
DanielJackson-Oslo committed Mar 2, 2024
1 parent edc4c44 commit b84f71d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 0 additions & 3 deletions app/controllers/facility_reviews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def create

return create_failed unless FacilityReview.create!(relevant_reviews)

# NB: Under the current model, this needs to happen before we add the descriptions with update_space_facilities,
# as aggregating DESTROYS all space_facilities, including the descriptions (wtf)
@space.aggregate_facility_reviews(facilities: @affected_facilities)
update_space_facilities(reviews_and_descriptions[:space_facilities_attributes].values)

create_succeeded
Expand Down
4 changes: 4 additions & 0 deletions app/models/facility_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class FacilityReview < ApplicationRecord

validates :space, uniqueness: { scope: [:user, :facility] }

after_commit do
space.aggregate_facility_reviews(facilities: [facility])
end

def experience_icon
ICON_FOR_EXPERIENCE[experience]
end
Expand Down

0 comments on commit b84f71d

Please sign in to comment.