reactions-fix

This commit is contained in:
tonyrewin 2022-09-14 16:10:38 +03:00
parent a585f2a8e0
commit 8fcd856132

View File

@ -97,12 +97,12 @@ async def update_reaction(_, info, inp):
@mutation.field("deleteReaction") @mutation.field("deleteReaction")
@login_required @login_required
async def delete_reaction(_, info, id): async def delete_reaction(_, info, rid):
auth = info.context["request"].auth auth = info.context["request"].auth
user_id = auth.user_id user_id = auth.user_id
with local_session() as session: with local_session() as session:
user = session.query(User).filter(User.id == user_id).first() user = session.query(User).filter(User.id == user_id).first()
reaction = session.query(Reaction).filter(Reaction.id == id).first() reaction = session.query(Reaction).filter(Reaction.id == rid).first()
if not reaction: if not reaction:
return {"error": "invalid reaction id"} return {"error": "invalid reaction id"}
if reaction.createdBy != user.slug: if reaction.createdBy != user.slug:
@ -114,13 +114,12 @@ async def delete_reaction(_, info, id):
@query.field("reactionsByShout") @query.field("reactionsByShout")
async def get_shout_reactions(_, info, slug, offset, limit): async def get_shout_reactions(_, info, slug, offset, limit):
offset = page * size
reactions = [] reactions = []
with local_session() as session: with local_session() as session:
reactions = ( reactions = (
session.query(Reaction) session.query(Reaction)
.filter(Reaction.shout == slug) .filter(Reaction.shout == slug)
.limit(size) .limit(limit)
.offset(offset) .offset(offset)
.all() .all()
) )
@ -131,7 +130,6 @@ async def get_shout_reactions(_, info, slug, offset, limit):
@query.field("reactionsForShouts") @query.field("reactionsForShouts")
async def get_reactions_for_shouts(_, info, shouts, offset, limit): async def get_reactions_for_shouts(_, info, shouts, offset, limit):
offset = page * size
reactions = [] reactions = []
with local_session() as session: with local_session() as session:
for slug in shouts: for slug in shouts:
@ -141,7 +139,7 @@ async def get_reactions_for_shouts(_, info, shouts, offset, limit):
.where(not bool(Reaction.deletedAt)) .where(not bool(Reaction.deletedAt))
.order_by(desc("createdAt")) .order_by(desc("createdAt"))
.offset(offset) .offset(offset)
.limit(size) .limit(limit)
.all() .all()
) )
for r in reactions: for r in reactions: