@@ -39,39 +39,28 @@ class Affiliation(
3939 entity_id = Column (ForeignKey ("entities.id" ), nullable = False , index = True )
4040 org_id = Column (ForeignKey ("orgs.id" ), nullable = False )
4141 certified_by_name = Column (String (100 ), nullable = True )
42- environment = Column (String (20 ), nullable = True , index = True )
4342
4443 entity = relationship ("Entity" , foreign_keys = [entity_id ], lazy = "select" )
4544 org = relationship ("Org" , foreign_keys = [org_id ], lazy = "select" )
4645
4746 @classmethod
48- def filter_environment (cls , environment : str ):
49- """Filter affiliation by environment."""
50- query = cls .query
51- if environment :
52- query = query .filter_by (environment = environment )
53- else :
54- query = query .filter (Affiliation .environment .is_ (None ))
55- return query
56-
57- @classmethod
58- def find_affiliation_by_org_and_entity_ids (cls , org_id : int , entity_id : int , environment ) -> Affiliation :
47+ def find_affiliation_by_org_and_entity_ids (cls , org_id : int , entity_id : int ) -> Affiliation :
5948 """Return an affiliation for the provided org and entity ids."""
60- query = cls .filter_environment ( environment ) .filter_by (org_id = int (org_id or - 1 ), entity_id = int (entity_id or - 1 ))
49+ query = cls .query .filter_by (org_id = int (org_id or - 1 ), entity_id = int (entity_id or - 1 ))
6150 return query .one_or_none ()
6251
6352 @classmethod
64- def find_affiliations_by_entity_id (cls , entity_id : int , environment ) -> List [Affiliation ]:
53+ def find_affiliations_by_entity_id (cls , entity_id : int ) -> List [Affiliation ]:
6554 """Return affiliations for the provided entity id."""
66- return cls .filter_environment ( environment ) .filter_by (entity_id = int (entity_id or - 1 )).all ()
55+ return cls .query .filter_by (entity_id = int (entity_id or - 1 )).all ()
6756
6857 @classmethod
6958 def find_affiliation_by_ids (cls , org_id : int , affiliation_id : int ) -> Affiliation :
7059 """Return the first Affiliation with the provided ids."""
7160 return cls .query .filter_by (org_id = int (org_id or - 1 )).filter_by (id = int (affiliation_id or - 1 )).one_or_none ()
7261
7362 @classmethod
74- def find_affiliations_by_org_id (cls , org_id : int , environment : str ) -> List [Affiliation ]:
63+ def find_affiliations_by_org_id (cls , org_id : int ) -> List [Affiliation ]:
7564 """Return the affiliations with the provided org id."""
7665 query = (
7766 db .session .query (Affiliation )
@@ -83,26 +72,15 @@ def find_affiliations_by_org_id(cls, org_id: int, environment: str) -> List[Affi
8372 )
8473 .filter (Affiliation .org_id == int (org_id or - 1 ))
8574 )
86- if environment :
87- query = query .filter (Affiliation .environment == environment )
88- else :
89- query = query .filter (Affiliation .environment .is_ (None ))
9075 return query .order_by (Affiliation .created .desc ()).all ()
9176
9277 @classmethod
93- def find_affiliations_by_business_identifier (cls , business_identifier : str , environment : str ):
78+ def find_affiliations_by_business_identifier (cls , business_identifier : str ):
9479 """Return the affiliations with the provided business identifier."""
95- return (
96- cls .filter_environment (environment )
97- .join (EntityModel )
98- .filter (EntityModel .business_identifier == business_identifier )
99- .all ()
100- )
80+ return cls .query .join (EntityModel ).filter (EntityModel .business_identifier == business_identifier ).all ()
10181
10282 @classmethod
103- def find_affiliation_by_org_id_and_business_identifier (
104- cls , org_id : int , business_identifier : str , environment : str
105- ) -> Affiliation :
83+ def find_affiliation_by_org_id_and_business_identifier (cls , org_id : int , business_identifier : str ) -> Affiliation :
10684 """Return the affiliations with the provided org id and business identifier."""
10785 query = (
10886 db .session .query (Affiliation )
@@ -115,8 +93,4 @@ def find_affiliation_by_org_id_and_business_identifier(
11593 .filter (Affiliation .org_id == int (org_id or - 1 ))
11694 .filter (EntityModel .business_identifier == business_identifier )
11795 )
118- if environment :
119- query = query .filter (Affiliation .environment == environment )
120- else :
121- query = query .filter (Affiliation .environment .is_ (None ))
12296 return query .first ()
0 commit comments