-
Notifications
You must be signed in to change notification settings - Fork 23
422 deactivate services when parent resource is deactivated #431
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Errors | ||
| class PreconditionFailed < StandardError; end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Services | ||
| module Resources | ||
| include Errors | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rails might auto-load this module, so I think it might be possible to delete this |
||
|
|
||
| def self.deactivate(id) | ||
| resource = Resource.find id | ||
| raise Errors::PreconditionFailed unless resource.approved? | ||
|
|
||
| resource.inactive! | ||
| remove_from_algolia(resource) | ||
| resource.services.each do |service| | ||
| Services.deactivate service | ||
| end | ||
| end | ||
|
|
||
| def self.remove_from_algolia(resource) | ||
| resource.remove_from_index! | ||
| rescue StandardError | ||
| puts 'failed to remove resource ' + resource.id.to_s + ' from algolia index' | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Services | ||
| module Services | ||
| include Errors | ||
|
|
||
| def self.deactivate(id) | ||
| service = Service.find id | ||
| raise Errors::PreconditionFailed unless service.approved? | ||
|
|
||
| service.inactive! | ||
| remove_from_algolia(service) | ||
| end | ||
|
|
||
| def self.remove_from_algolia(service) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this can be factored out as a common utility since it is used in both services? Might be able to put it in def self.remove_from_algolia(record)
record.remove_from_index!
rescue StandardError
puts "failed to remove #{record.class} #{record.id} from algolia index"
end |
||
| service.remove_from_index! | ||
| rescue StandardError | ||
| puts 'failed to remove service ' + service.id.to_s + ' from algolia index' | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be cool to add some rspec tests for these services, but if their functionality is already covered by the Postman tests, there is probably no need.