From c92e55c3ad537e8845db501cabda360acb6915af Mon Sep 17 00:00:00 2001 From: utibe solomon Date: Wed, 14 Aug 2024 01:22:55 +0100 Subject: [PATCH] Feat added invitations endpoint --- api/v1/routes/organisation.py | 3 ++- api/v1/services/invite.py | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/v1/routes/organisation.py b/api/v1/routes/organisation.py index 842a241ac..c0568908a 100644 --- a/api/v1/routes/organisation.py +++ b/api/v1/routes/organisation.py @@ -134,9 +134,10 @@ def get_organization_invites( current_user : User = Depends(user_service.get_current_super_admin), ) : invitations = invite.InviteService.fetch_all(db) + return success_response( status_code=status.HTTP_200_OK, message='Invites fetched succesfully', - data=[jsonable_encoder(invitation) for invitation in invitations] + data=[jsonable_encoder(invitation, exclude=['user_id','organisation_id']) for invitation in invitations] ) diff --git a/api/v1/services/invite.py b/api/v1/services/invite.py index f50407619..bb445b9bb 100644 --- a/api/v1/services/invite.py +++ b/api/v1/services/invite.py @@ -1,7 +1,7 @@ import logging from datetime import datetime, timedelta from pytz import utc -from sqlalchemy.orm import Session +from sqlalchemy.orm import Session,joinedload from sqlalchemy import insert from fastapi import HTTPException, Request, Depends, status from collections import OrderedDict @@ -9,6 +9,7 @@ from api.v1.models.invitation import Invitation from api.v1.models.organisation import Organisation from api.v1.models.user import User +from api.v1.services.user import user_service from sqlalchemy.exc import IntegrityError from api.v1.models.permissions.role import Role from api.v1.schemas.permissions.roles import RoleCreate @@ -214,7 +215,10 @@ def fetch(self): @staticmethod def fetch_all(session : Session): - all_invites = session.query(Invitation).all() + all_invites = session.query(Invitation).options(joinedload(Invitation.organisation)).all() + for invite in all_invites : + user = user_service.get_user_by_id(db=session , id=invite.user_id) + invite.email = user.email return all_invites def update(self): pass