2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
module Users
|
|
|
|
class RespondToTermsService
|
|
|
|
def initialize(user, term)
|
2021-04-29 21:17:54 +05:30
|
|
|
@user = user
|
|
|
|
@term = term
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-10-15 14:42:47 +05:30
|
|
|
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-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def store_accepted_term(accepted)
|
|
|
|
@user.update_column(:accepted_term_id, accepted ? @term.id : nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|