2018-07-18 12:03:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-27 08:56:50 -04:00
|
|
|
module Users
|
|
|
|
class RespondToTermsService
|
|
|
|
def initialize(user, term)
|
|
|
|
@user, @term = user, term
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-04-27 08:56:50 -04:00
|
|
|
def execute(accepted:)
|
|
|
|
agreement = @user.term_agreements.find_or_initialize_by(term: @term)
|
|
|
|
agreement.accepted = accepted
|
|
|
|
|
|
|
|
if agreement.save
|
|
|
|
store_accepted_term(accepted)
|
|
|
|
end
|
|
|
|
|
|
|
|
agreement
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-04-27 08:56:50 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def store_accepted_term(accepted)
|
|
|
|
@user.update_column(:accepted_term_id, accepted ? @term.id : nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|