This commit is contained in:
parent
0240005ed1
commit
a21efb99df
|
@ -16,10 +16,10 @@ class Invite(Base):
|
||||||
__tablename__ = "invite"
|
__tablename__ = "invite"
|
||||||
|
|
||||||
inviter_id = Column(ForeignKey("author.id"), nullable=False, index=True)
|
inviter_id = Column(ForeignKey("author.id"), nullable=False, index=True)
|
||||||
invitee_id = Column(ForeignKey("author.id"), nullable=False, index=True)
|
author_id = Column(ForeignKey("author.id"), nullable=False, index=True)
|
||||||
shout_id = Column(ForeignKey("shout.id"), nullable=False, index=True)
|
shout_id = Column(ForeignKey("shout.id"), nullable=False, index=True)
|
||||||
status = Column(Enum(InviteStatus), default=InviteStatus.PENDING)
|
status = Column(Enum(InviteStatus), default=InviteStatus.PENDING)
|
||||||
|
|
||||||
inviter = relationship(Author, foreign_keys=[inviter_id])
|
inviter = relationship(Author, foreign_keys=[inviter_id])
|
||||||
invitee = relationship(Author, foreign_keys=[invitee_id])
|
author = relationship(Author, foreign_keys=[author_id])
|
||||||
shout = relationship(Shout)
|
shout = relationship(Shout)
|
||||||
|
|
|
@ -17,7 +17,7 @@ async def accept_invite(_, info, invite_id: int):
|
||||||
if author:
|
if author:
|
||||||
# Check if the invite exists
|
# Check if the invite exists
|
||||||
invite = session.query(Invite).filter(Invite.id == invite_id).first()
|
invite = session.query(Invite).filter(Invite.id == invite_id).first()
|
||||||
if invite and invite.invitee_id == author.id and invite.status == InviteStatus.PENDING:
|
if invite and invite.author_id == author.id and invite.status == InviteStatus.PENDING:
|
||||||
# Add the user to the shout authors
|
# Add the user to the shout authors
|
||||||
shout = session.query(Shout).filter(Shout.id == invite.shout_id).first()
|
shout = session.query(Shout).filter(Shout.id == invite.shout_id).first()
|
||||||
if shout:
|
if shout:
|
||||||
|
@ -44,7 +44,7 @@ async def reject_invite(_, info, invite_id: int):
|
||||||
if author:
|
if author:
|
||||||
# Check if the invite exists
|
# Check if the invite exists
|
||||||
invite = session.query(Invite).filter(Invite.id == invite_id).first()
|
invite = session.query(Invite).filter(Invite.id == invite_id).first()
|
||||||
if invite and invite.invitee_id == author.id and invite.status == InviteStatus.PENDING:
|
if invite and invite.author_id == author.id and invite.status == InviteStatus.PENDING:
|
||||||
# Delete the invite
|
# Delete the invite
|
||||||
session.delete(invite)
|
session.delete(invite)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
@ -64,15 +64,15 @@ async def create_invite(_, info, slug: str = "", author_id: int = None, user: st
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
||||||
if shout and shout.authors and user_id in [author.id for author in shout.authors]:
|
if shout and shout.authors and user_id in [author.id for author in shout.authors]:
|
||||||
# Check if the invitee is a valid author
|
# Check if the author is a valid author
|
||||||
invitee = session.query(Author).filter(Author.id == author_id).first()
|
author = session.query(Author).filter(Author.id == author_id).first()
|
||||||
if invitee:
|
if author:
|
||||||
# Check if an invite already exists
|
# Check if an invite already exists
|
||||||
existing_invite = (
|
existing_invite = (
|
||||||
session.query(Invite)
|
session.query(Invite)
|
||||||
.filter(
|
.filter(
|
||||||
Invite.inviter_id == user_id,
|
Invite.inviter_id == user_id,
|
||||||
Invite.invitee_id == author_id,
|
Invite.author_id == author_id,
|
||||||
Invite.shout_id == shout.id,
|
Invite.shout_id == shout.id,
|
||||||
Invite.status == InviteStatus.PENDING,
|
Invite.status == InviteStatus.PENDING,
|
||||||
)
|
)
|
||||||
|
@ -83,14 +83,14 @@ async def create_invite(_, info, slug: str = "", author_id: int = None, user: st
|
||||||
|
|
||||||
# Create a new invite
|
# Create a new invite
|
||||||
new_invite = Invite(
|
new_invite = Invite(
|
||||||
inviter_id=user_id, invitee_id=author_id, shout_id=shout.id, status=InviteStatus.PENDING
|
inviter_id=user_id, author_id=author_id, shout_id=shout.id, status=InviteStatus.PENDING
|
||||||
)
|
)
|
||||||
session.add(new_invite)
|
session.add(new_invite)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
return {"error": None, "invite": new_invite}
|
return {"error": None, "invite": new_invite}
|
||||||
else:
|
else:
|
||||||
return {"error": "Invalid invitee"}
|
return {"error": "Invalid author"}
|
||||||
else:
|
else:
|
||||||
return {"error": "Access denied"}
|
return {"error": "Access denied"}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,14 @@ enum FollowingEntity {
|
||||||
REACTIONS
|
REACTIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum InviteStatus {
|
||||||
|
PENDING
|
||||||
|
ACCEPTED
|
||||||
|
REJECTED
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Типы
|
# Типы
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,6 +181,14 @@ type Topic {
|
||||||
oid: String
|
oid: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Invite {
|
||||||
|
id: Int!
|
||||||
|
inviter_id: Int!
|
||||||
|
author_id: Int!
|
||||||
|
shout_id: Int!
|
||||||
|
status: InviteStatus
|
||||||
|
}
|
||||||
|
|
||||||
# Входные типы
|
# Входные типы
|
||||||
|
|
||||||
input ShoutInput {
|
input ShoutInput {
|
||||||
|
@ -288,6 +304,7 @@ type Result {
|
||||||
communities: [Community]
|
communities: [Community]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Мутации
|
# Мутации
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user