Skip to content

Commit 5c87f0e

Browse files
committed
fix: Refactor query #121
1 parent 0717104 commit 5c87f0e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

time_tracker_api/projects/projects_model.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,11 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
6868
event_ctx = self.create_event_context("read-many")
6969
customer_dao = customers_create_dao()
7070
customers = customer_dao.get_all()
71-
projects = self.repository.find_all(event_ctx, **kwargs)
72-
active_projects = []
73-
74-
for project in projects:
75-
for customer in customers:
76-
if customer in project:
77-
active_projects.append(project)
78-
break
79-
return active_projects
71+
72+
customers_id = [customer.id for customer in customers]
73+
conditions = conditions if conditions else {}
74+
custom_condition = "c.customer_id IN {}".format(str(tuple(customers_id)))
75+
return self.repository.find_all(event_ctx, conditions, custom_sql_conditions=[custom_condition], **kwargs)
8076

8177

8278
def create_dao() -> ProjectDao:

0 commit comments

Comments
 (0)