From c9205a698f7144498cda870d8ff1d40ca3c7c75b Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 5 May 2024 00:00:58 +0300 Subject: [PATCH] typo-fix --- resolvers/author.py | 2 +- resolvers/reaction.py | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index 5cf6e0fe..a7331085 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -150,7 +150,7 @@ async def load_authors_by(_, _info, by, limit, offset): q = q.limit(limit).offset(offset) - authors_nostat = local_session().session(q) + authors_nostat = local_session().execute(q) authors = [] if authors_nostat: for [a] in authors_nostat: diff --git a/resolvers/reaction.py b/resolvers/reaction.py index 40c11d3f..688a4c15 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -175,26 +175,28 @@ def prepare_new_rating(reaction: dict, shout_id: int, session, author_id: int): Reaction.shout == shout_id, Reaction.created_by == author_id, Reaction.kind.in_(RATING_REACTIONS), + Reaction.deleted_at.is_not(None), ) ) reply_to = reaction.get("reply_to") if reply_to and isinstance(reply_to, int): q = q.filter(Reaction.reply_to == reply_to) rating_reactions = session.execute(q).all() - same_rating = filter( - lambda r: r.created_by == author_id and r.kind == kind, - rating_reactions, - ) - opposite_rating = filter( - lambda r: r.created_by == author_id and r.kind == opposite_kind, - rating_reactions, - ) - if same_rating: - return {"error": "You can't rate the same thing twice"} - elif opposite_rating: - return {"error": "Remove opposite vote first"} - elif filter(lambda r: r.created_by == author_id, rating_reactions): - return {"error": "You can't rate your own thing"} + if rating_reactions: + same_rating = filter( + lambda r: r.created_by == author_id and r.kind == kind, + rating_reactions, + ) + opposite_rating = filter( + lambda r: r.created_by == author_id and r.kind == opposite_kind, + rating_reactions, + ) + if same_rating: + return {"error": "You can't rate the same thing twice"} + elif opposite_rating: + return {"error": "Remove opposite vote first"} + elif filter(lambda r: r.created_by == author_id, rating_reactions): + return {"error": "You can't rate your own thing"} return