Return the invitation data after accept/decline

This commit is contained in:
Peter Vacho 2025-01-04 16:43:34 +01:00
parent 49946660c3
commit 516bac573a
Signed by: school
GPG key ID: 8CFC3837052871B4

View file

@ -224,7 +224,7 @@ async def delete_invitation(invitation_id: PydanticObjectId, user: CurrentUserDe
@invitations_router.post("/{invitation_id}/accept")
async def accept_invitation(invitation_id: PydanticObjectId, user: CurrentUserDep) -> Response:
async def accept_invitation(invitation_id: PydanticObjectId, user: CurrentUserDep) -> InvitationData:
"""Accept an invitation."""
invitation = await Invitation.get(invitation_id, fetch_links=True)
if invitation is None:
@ -242,7 +242,7 @@ async def accept_invitation(invitation_id: PydanticObjectId, user: CurrentUserDe
# Mark the invitation as accepted
invitation.status = "accepted"
invitation.responded_at = datetime.now(tz=UTC)
_ = await invitation.save()
_ = await invitation.replace()
# Add the user to the event
event = invitation.event
@ -262,11 +262,11 @@ async def accept_invitation(invitation_id: PydanticObjectId, user: CurrentUserDe
)
notification = await notification.create()
return Response(status_code=status.HTTP_204_NO_CONTENT)
return InvitationData.from_invitation(invitation)
@invitations_router.post("/{invitation_id}/decline")
async def decline_invitation(invitation_id: PydanticObjectId, user: CurrentUserDep) -> Response:
async def decline_invitation(invitation_id: PydanticObjectId, user: CurrentUserDep) -> InvitationData:
"""Decline an invitation."""
invitation = await Invitation.get(invitation_id, fetch_links=True)
if invitation is None:
@ -283,7 +283,7 @@ async def decline_invitation(invitation_id: PydanticObjectId, user: CurrentUserD
invitation.status = "declined"
invitation.responded_at = datetime.now(tz=UTC)
_ = await invitation.save()
_ = await invitation.replace()
# Send back a notification to the invitor about the decline
notification = Notification(
@ -295,7 +295,7 @@ async def decline_invitation(invitation_id: PydanticObjectId, user: CurrentUserD
)
notification = await notification.create()
return Response(status_code=status.HTTP_204_NO_CONTENT)
return InvitationData.from_invitation(invitation)
router = APIRouter()