create-reaction-debug-6
This commit is contained in:
parent
31f2414064
commit
257ff43eaa
|
@ -165,7 +165,6 @@ def set_hidden(session, shout_id):
|
||||||
session.add(s)
|
session.add(s)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("create_reaction")
|
@mutation.field("create_reaction")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_reaction(_, info, reaction):
|
async def create_reaction(_, info, reaction):
|
||||||
|
@ -183,15 +182,18 @@ async def create_reaction(_, info, reaction):
|
||||||
|
|
||||||
if shout and author:
|
if shout and author:
|
||||||
reaction["created_by"] = author.id
|
reaction["created_by"] = author.id
|
||||||
|
kind = reaction.get("kind")
|
||||||
if reaction["kind"] in [ReactionKind.DISLIKE.value, ReactionKind.LIKE.value]:
|
if not kind and reaction.get("body"):
|
||||||
|
kind = ReactionKind.COMMENT.value
|
||||||
|
if not kind:
|
||||||
|
return { "error": "cannot create reaction with this kind"}
|
||||||
existing_reaction = (
|
existing_reaction = (
|
||||||
session.query(Reaction)
|
session.query(Reaction)
|
||||||
.filter(
|
.filter(
|
||||||
and_(
|
and_(
|
||||||
Reaction.shout == reaction["shout"],
|
Reaction.shout == shout_id,
|
||||||
Reaction.created_by == author.id,
|
Reaction.created_by == author.id,
|
||||||
Reaction.kind == reaction["kind"],
|
Reaction.kind == kind,
|
||||||
Reaction.reply_to == reaction.get("reply_to"),
|
Reaction.reply_to == reaction.get("reply_to"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -245,6 +247,7 @@ async def create_reaction(_, info, reaction):
|
||||||
session.commit()
|
session.commit()
|
||||||
logger.debug(r)
|
logger.debug(r)
|
||||||
rdict = r.dict()
|
rdict = r.dict()
|
||||||
|
|
||||||
# Self-regulation mechanics
|
# Self-regulation mechanics
|
||||||
if check_to_hide(session, r):
|
if check_to_hide(session, r):
|
||||||
set_hidden(session, r.shout)
|
set_hidden(session, r.shout)
|
||||||
|
@ -308,8 +311,8 @@ async def update_reaction(_, info, rid, reaction):
|
||||||
|
|
||||||
return {"reaction": r}
|
return {"reaction": r}
|
||||||
else:
|
else:
|
||||||
return {"error": "user"}
|
return {"error": "not authorized"}
|
||||||
|
return {"error": "cannot create reaction"}
|
||||||
|
|
||||||
@mutation.field("delete_reaction")
|
@mutation.field("delete_reaction")
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in New Issue
Block a user