Skip to content

Commit cd20183

Browse files
committed
fix: Filter projects by active customers #121
1 parent 59e8efb commit cd20183

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

time_tracker_api/projects/projects_model.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from commons.data_access_layer.cosmos_db import CosmosDBModel, CosmosDBDao, CosmosDBRepository
44
from time_tracker_api.database import CRUDDao, APICosmosDBDao
55
from time_tracker_api.customers.customers_model import create_dao as customers_create_dao
6+
from time_tracker_api.customers.customers_model import CustomerCosmosDBModel
67

78

89
class ProjectDao(CRUDDao):
@@ -33,6 +34,12 @@ class ProjectCosmosDBModel(CosmosDBModel):
3334
def __init__(self, data):
3435
super(ProjectCosmosDBModel, self).__init__(data) # pragma: no cover
3536

37+
def __contains__(self, item):
38+
if type(item) is CustomerCosmosDBModel:
39+
return True if item.id == self.customer_id else False
40+
else:
41+
raise NotImplementedError
42+
3643
def __repr__(self):
3744
return '<Project %r>' % self.name # pragma: no cover
3845

@@ -52,14 +59,26 @@ def __init__(self, repository):
5259
CosmosDBDao.__init__(self, repository)
5360

5461
def get_all(self, conditions: dict = None, **kwargs) -> list:
62+
"""
63+
Get all the projects an active client has
64+
:param (dict) conditions: Conditions for querying the database
65+
:param (dict) kwargs: Pass arguments
66+
:return (list): ProjectCosmosDBModel object list
67+
"""
5568
event_ctx = self.create_event_context("read-many")
5669
customer_dao = customers_create_dao()
57-
customers = customer_dao.get_all(visible_only=False)
70+
customers = customer_dao.get_all()
5871
projects = self.repository.find_all(event_ctx, **kwargs)
59-
for project in projects:
60-
print(project.__dict__)
72+
active_projects = []
6173

62-
return projects
74+
for project in projects:
75+
find = False
76+
for customer in customers:
77+
if customer in project:
78+
find = True
79+
if find:
80+
active_projects.append(project)
81+
return active_projects
6382

6483

6584
def create_dao() -> ProjectDao:

0 commit comments

Comments
 (0)