From 4848aeefc93cc483e4b2a524fc611c5b64c301b1 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Mon, 6 Feb 2023 16:15:47 +0300 Subject: [PATCH 1/4] [hotfix] add ID to updateReaction --- resolvers/zine/reactions.py | 9 +++++---- schema.graphql | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/resolvers/zine/reactions.py b/resolvers/zine/reactions.py index 071e5b38..4e9485e2 100644 --- a/resolvers/zine/reactions.py +++ b/resolvers/zine/reactions.py @@ -201,13 +201,14 @@ async def create_reaction(_, info, reaction={}): @mutation.field("updateReaction") @login_required -async def update_reaction(_, info, reaction={}): +async def update_reaction(_, info, id, reaction={}): auth: AuthCredentials = info.context["request"].auth with local_session() as session: user = session.query(User).where(User.id == auth.user_id).first() - q = select(Reaction).filter(Reaction.id == reaction['id']) + q = select(Reaction).filter(Reaction.id == id) q = add_reaction_stat_columns(q) + q = q.group_by(Reaction.id) [r, reacted_stat, commented_stat, rating_stat] = session.execute(q).unique().one() @@ -235,12 +236,12 @@ async def update_reaction(_, info, reaction={}): @mutation.field("deleteReaction") @login_required -async def delete_reaction(_, info, reaction=None): +async def delete_reaction(_, info, id): # NOTE: reaction is id auth: AuthCredentials = info.context["request"].auth with local_session() as session: - r = session.query(Reaction).filter(Reaction.id == reaction).first() + r = session.query(Reaction).filter(Reaction.id == id).first() if not r: return {"error": "invalid reaction id"} if r.createdBy != auth.user_id: diff --git a/schema.graphql b/schema.graphql index 7f30b8ae..f780d0fb 100644 --- a/schema.graphql +++ b/schema.graphql @@ -198,8 +198,8 @@ type Mutation { # reactions createReaction(reaction: ReactionInput!): Result! - updateReaction(reaction: ReactionInput!): Result! - deleteReaction(reaction: Int!): Result! + updateReaction(id: Int!, reaction: ReactionInput!): Result! + deleteReaction(id: Int!): Result! # draft / collab createDraft(draft: DraftInput!): Result! From acc71415a9d9a476ba68e1aa1aa90bafea99b6e6 Mon Sep 17 00:00:00 2001 From: bniwredyc Date: Sun, 12 Feb 2023 04:27:55 +0100 Subject: [PATCH 2/4] loadReactionsBy kind fix --- resolvers/zine/reactions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resolvers/zine/reactions.py b/resolvers/zine/reactions.py index 071e5b38..3c32d3ec 100644 --- a/resolvers/zine/reactions.py +++ b/resolvers/zine/reactions.py @@ -257,7 +257,7 @@ async def load_reactions_by(_, _info, by, limit=50, offset=0): """ :param by: { :shout - filter by slug - :shouts - filer by shouts luglist + :shouts - filer by shout slug list :createdBy - to filter by author :topic - to filter by topic :search - to search by reactions' body @@ -324,6 +324,9 @@ async def load_reactions_by(_, _info, by, limit=50, offset=0): "commented": commented_stat, "reacted": reacted_stat } + + reaction.kind = reaction.kind.name + reactions.append(reaction) # ? From 1fab93ac61ef5f7919919c5578363deb41fd3155 Mon Sep 17 00:00:00 2001 From: bniwredyc Date: Sun, 12 Feb 2023 15:18:57 +0100 Subject: [PATCH 3/4] reaction rating fix --- resolvers/zine/reactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolvers/zine/reactions.py b/resolvers/zine/reactions.py index 3c32d3ec..afb01199 100644 --- a/resolvers/zine/reactions.py +++ b/resolvers/zine/reactions.py @@ -14,7 +14,7 @@ from orm.user import User def add_reaction_stat_columns(q): aliased_reaction = aliased(Reaction) - q = q.outerjoin(aliased_reaction).add_columns( + q = q.outerjoin(aliased_reaction, Reaction.id == aliased_reaction.replyTo).add_columns( func.sum( aliased_reaction.id ).label('reacted_stat'), From aa65eeb07f9eb36117891c378aafb33b9b81bbb5 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Mon, 13 Feb 2023 14:53:41 +0300 Subject: [PATCH 4/4] [hotfix] userFollowers fix --- resolvers/zine/profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolvers/zine/profile.py b/resolvers/zine/profile.py index c70106df..a875fbf9 100644 --- a/resolvers/zine/profile.py +++ b/resolvers/zine/profile.py @@ -132,7 +132,7 @@ async def user_followers(_, _info, slug) -> List[User]: q = add_author_stat_columns(q) aliased_user = aliased(User) - q = q.join(AuthorFollower).join( + q = q.join(AuthorFollower, AuthorFollower.follower == User.id).join( aliased_user, aliased_user.id == AuthorFollower.author ).where( aliased_user.slug == slug