Coverage for modules\notifications\services.py: 58%

12 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-05 09:25 +0800

1from django.utils import timezone 

2from .models import Notification 

3 

4class NotificationService: 

5 @staticmethod 

6 def send_notification(tenant_id, recipient, type, title, message, link_url=None): 

7 notif = Notification.objects.create( 

8 tenant_id=tenant_id, 

9 recipient=recipient, 

10 type=type, 

11 title=title, 

12 message=message, 

13 link_url=link_url 

14 ) 

15 return notif 

16 

17 @staticmethod 

18 def mark_as_read(tenant_id, user, notification_id=None): 

19 if notification_id: 

20 Notification.objects.filter(id=notification_id, recipient=user, tenant_id=tenant_id).update( 

21 is_read=True, 

22 read_at=timezone.now() 

23 ) 

24 else: 

25 Notification.objects.filter(recipient=user, tenant_id=tenant_id, is_read=False).update( 

26 is_read=True, 

27 read_at=timezone.now() 

28 )