This commit is contained in:
@@ -24,7 +24,7 @@ class Notification:
|
||||
|
||||
@strawberry.type
|
||||
class NotificationSeenResult:
|
||||
error: str
|
||||
error: str = strawberry.field(default=None, name="error")
|
||||
|
||||
|
||||
@strawberry.type
|
||||
@@ -40,7 +40,6 @@ class Query:
|
||||
@login_required
|
||||
async def load_notifications(self, info, limit: int = 50, offset: int = 0) -> NotificationsResult:
|
||||
user_id = info.context["user_id"]
|
||||
nr = NotificationsResult()
|
||||
with local_session() as session:
|
||||
author = session.query(Author).filter(Author.user == user_id).first()
|
||||
NotificationSeenAlias = aliased(NotificationSeen)
|
||||
@@ -53,7 +52,7 @@ class Query:
|
||||
NotificationSeen,
|
||||
and_(NotificationSeen.viewer == author.id, NotificationSeen.notification == NotificationMessage.id),
|
||||
).limit(limit).offset(offset).all()
|
||||
nr.notifications = []
|
||||
notifications = []
|
||||
for n in nnn:
|
||||
ntf = Notification()
|
||||
ntf.id = n.id
|
||||
@@ -62,10 +61,18 @@ class Query:
|
||||
ntf.action = n.action
|
||||
ntf.created_at = n.created_at
|
||||
ntf.seen = n.seen
|
||||
nr.notifications.append(ntf)
|
||||
nr.unread = sum(1 for n in nr.notifications if author.id in n.seen)
|
||||
nr.total = session.query(NotificationMessage).count()
|
||||
return nr
|
||||
notifications.append(ntf)
|
||||
nr = NotificationsResult(
|
||||
notifications = notifications,
|
||||
unread = sum(1 for n in notifications if author.id in n.seen),
|
||||
total = session.query(NotificationMessage).count()
|
||||
)
|
||||
return nr
|
||||
return NotificationsResult(
|
||||
notifications=[],
|
||||
total = 0,
|
||||
unread = 0
|
||||
)
|
||||
|
||||
|
||||
@strawberry.type
|
||||
@@ -83,8 +90,7 @@ class Mutation:
|
||||
except Exception as e:
|
||||
session.rollback()
|
||||
print(f"[mark_notification_as_read] error: {str(e)}")
|
||||
nsr = NotificationSeenResult()
|
||||
nsr.error = "cant mark as read"
|
||||
nsr = NotificationSeenResult(error = "cant mark as read")
|
||||
return nsr
|
||||
return NotificationSeenResult()
|
||||
|
||||
|
Reference in New Issue
Block a user