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.
educoder/app/services/reward_grade_service.rb

19 lines
489 B

6 years ago
class RewardGradeService < ApplicationService
attr_reader :user, :attrs, :not_unique
6 years ago
def initialize(user, **attrs)
@user = user
@not_unique = attrs.delete(:not_unique) || false
6 years ago
@attrs = attrs.slice(*%i[container_id container_type score])
end
def call
return if user.grades.exists?(attrs) && !not_unique
6 years ago
ActiveRecord::Base.transaction do
grade = user.grades.create!(attrs)
user.increment!(:grade, grade.score)
end
end
end