From 253cfefabb8648169bc1a86db84c19ce4fb25b07 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 9 Jan 2024 12:40:12 +0000 Subject: [PATCH] feat: add active scope --- app/models/notification.rb | 2 ++ app/models/user.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 9e3a8482f..f136948f6 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,3 +1,5 @@ class Notification < ApplicationRecord acts_as_readable + + scope :active, -> { where("start_date <= ?", Time.zone.now).where("end_date >= ?", Time.zone.now) } end diff --git a/app/models/user.rb b/app/models/user.rb index 1aa7898e1..1f6412b6a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -230,7 +230,7 @@ class User < ApplicationRecord end def active_unread_notifications - Notification.unread_by(self) + Notification.active.unread_by(self) end def oldest_active_unread_notification