Skip to content

Commit

Permalink
Force conver string to int part 2. (#3034)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwei1018 authored Sep 20, 2024
2 parents 5351494 + 696ad16 commit 3364f24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions auth-api/src/auth_api/models/affiliation_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,39 @@ def filter_by(cls, search_filter: AffiliationInvitationSearch, query=None) -> li
results = db.session.query(AffiliationInvitation)

if search_filter.from_org_id:
results = results.filter(AffiliationInvitation.from_org_id == int(search_filter.from_org_id))
results = results.filter(
AffiliationInvitation.from_org_id.cast(Integer) == search_filter.from_org_id.cast(Integer)
)
filter_set = True

if search_filter.to_org_id:
results = results.filter(AffiliationInvitation.to_org_id == int(search_filter.to_org_id))
results = results.filter(
AffiliationInvitation.to_org_id.cast(Integer) == search_filter.to_org_id.cast(Integer)
)
filter_set = True

if search_filter.sender_id:
results = results.filter(AffiliationInvitation.sender_id == int(search_filter.sender_id))
results = results.filter(
AffiliationInvitation.sender_id.cast(Integer) == search_filter.sender_id.cast(Integer)
)
filter_set = True

if search_filter.approver_id:
results = results.filter(AffiliationInvitation.approver_id == int(search_filter.approver_id))
results = results.filter(
AffiliationInvitation.approver_id.cast(Integer) == search_filter.approver_id.cast(Integer)
)
filter_set = True

if search_filter.entity_id:
results = results.filter(AffiliationInvitation.entity_id == int(search_filter.entity_id))
results = results.filter(
AffiliationInvitation.entity_id.cast(Integer) == search_filter.entity_id.cast(Integer)
)
filter_set = True

if search_filter.affiliation_id:
results = results.filter(AffiliationInvitation.affiliation_id == int(search_filter.affiliation_id))
results = results.filter(
AffiliationInvitation.affiliation_id.cast(Integer) == search_filter.affiliation_id.cast(Integer)
)
filter_set = True

if search_filter.status_codes:
Expand Down
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/models/invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def find_invitation_by_id(cls, invitation_id: int):
@classmethod
def find_invitations_by_org(cls, org_id: int, status=None):
"""Find all invitations sent for specific org filtered by status."""
results = cls.query.filter(Invitation.membership.any(InvitationMembership.org_id == org_id))
results = cls.query.filter(Invitation.membership.any(InvitationMembership.org_id.cast(Integer) == org_id))
return results.filter(Invitation.status == status.value).all() if status else results.all()

@staticmethod
Expand Down

0 comments on commit 3364f24

Please sign in to comment.