notification-model-fix

This commit is contained in:
2024-01-23 12:05:28 +03:00
parent 140e46e9f2
commit ac424cf803
3 changed files with 17 additions and 17 deletions

View File

@@ -6,7 +6,7 @@ from resolvers.model import (
NotificationAuthor,
NotificationsResult,
)
from orm.notification import NotificationSeen, Notification
from orm.notification import NotificationAction, NotificationEntity, NotificationSeen, Notification
from typing import Dict, List
import time, json
import strawberry
@@ -59,8 +59,8 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
notifications_by_thread: Dict[str, List[Notification]] = {}
groups_by_thread: Dict[str, NotificationGroup] = {}
with local_session() as session:
total = session.query(Notification).filter(and_(Notification.action == "create", Notification.created_at > after)).count()
unread = session.query(Notification).filter(and_(Notification.action == "create", Notification.created_at > after, Notification.seen.is_not(True))).count()
total = session.query(Notification).filter(and_(Notification.action == NotificationAction.CREATE.value, Notification.created_at > after)).count()
unread = session.query(Notification).filter(and_(Notification.action == NotificationAction.CREATE.value, Notification.created_at > after, Notification.seen.is_not(True))).count()
notifications_result = session.execute(query)
for n, seen in notifications_result:
thread_id = ""
@@ -87,7 +87,7 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
notifications.append(n)
notifications_by_thread[thread_id] = notifications
groups_amount += 1
elif n.entity == "reaction" and n.action == "create":
elif n.entity == NotificationEntity.REACTION.value and n.action == NotificationAction.CREATE.value:
reaction: NotificationReaction = payload
shout: NotificationShout = reaction.shout
thread_id += f"{reaction.shout}"