Reintroduce function in business logic

This commit is contained in:
Guille Gutierrez 2023-03-13 15:01:55 -04:00
parent a3a382dae9
commit ecb09edcfb

View File

@ -86,17 +86,20 @@ class User(Repository):
except SQLAlchemyError as err:
logger.error(f'Error while fetching user: {err}')
def get_by_name_and_application(self, name: str, application_id: int) -> Model:
def get_by_name_and_application(self, name: str, application_id: int) -> Union[Model, None]:
"""
Fetch user based on the email address
:param name: User name
:param application_id: User application name
:return: [User] matching the search criteria
:return: User matching the search criteria or None
"""
try:
return self.session.execute(
user = self.session.execute(
select(Model).where(Model.name == name, Model.application_id == application_id)
).first()[0]
).first()
if user is not None:
user = user[0]
return user
except SQLAlchemyError as err:
logger.error(f'Error while fetching user by name and application: {err}')