You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
519 B
24 lines
519 B
class RewardExperienceService
|
|
attr_reader :user, :attrs
|
|
|
|
def initialize(user, **attrs)
|
|
@user = user
|
|
@attrs = attrs.slice(*%i[container_id container_type score])
|
|
end
|
|
|
|
def call
|
|
return if user.experiences.exists?(attrs.except(:score))
|
|
|
|
ActiveRecord::Base.transaction do
|
|
experience = user.experiences.create!(attrs)
|
|
|
|
user.increment!(:experience, experience.score)
|
|
|
|
experience
|
|
end
|
|
end
|
|
|
|
def self.call(user, **attrs)
|
|
new(user, attrs).call
|
|
end
|
|
end |