Skip to content
Snippets Groups Projects
Commit 4cbcb212 authored by tmn21's avatar tmn21 :rocket:
Browse files

ISSUE #38: CREATE streak route

parent 5b1d8010
No related branches found
No related tags found
No related merge requests found
Pipeline #34088 failed
......@@ -79,6 +79,8 @@
# level :integer default("1")
# points :integer default("0")
# last_sign_in_day :datetime
# last_action_at :date
# streak :integer default("0")
class User < ApplicationRecord
include Followable
......@@ -385,6 +387,27 @@ class User < ApplicationRecord
end
end
def update_streak()
if self.last_action_at==Date.today
return
end
# increase streak count
if self.last_action_at==Date.yesterday
self.update(last_action_at: Date.today)
self.update(streak: streak+1)
return
end
# restart streak count
if Date.today - self.last_action_at >= 2
self.update(last_action_at: Date.today)
self.update(streak: 1)
end
end
def complete_action(action, quantity=1)
return false, { "error": "action not found"} if action.blank?
......
......@@ -62,6 +62,7 @@ class View < ApplicationRecord
if !user.nil?
if viewable_type == "LearningObject"
user.complete_action(Action.find_by_name("Visualizar um Recurso"))
user.update_streak()
viewable.subjects.each do |subject|
user.complete_action(Action.find_by_name("Visualizar um Recurso de #{subject.name}"))
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment