3
3
from commons .data_access_layer .cosmos_db import CosmosDBModel , CosmosDBDao , CosmosDBRepository
4
4
from time_tracker_api .database import CRUDDao , APICosmosDBDao
5
5
from time_tracker_api .customers .customers_model import create_dao as customers_create_dao
6
+ from time_tracker_api .customers .customers_model import CustomerCosmosDBModel
6
7
7
8
8
9
class ProjectDao (CRUDDao ):
@@ -33,6 +34,12 @@ class ProjectCosmosDBModel(CosmosDBModel):
33
34
def __init__ (self , data ):
34
35
super (ProjectCosmosDBModel , self ).__init__ (data ) # pragma: no cover
35
36
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
+
36
43
def __repr__ (self ):
37
44
return '<Project %r>' % self .name # pragma: no cover
38
45
@@ -52,14 +59,26 @@ def __init__(self, repository):
52
59
CosmosDBDao .__init__ (self , repository )
53
60
54
61
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
+ """
55
68
event_ctx = self .create_event_context ("read-many" )
56
69
customer_dao = customers_create_dao ()
57
- customers = customer_dao .get_all (visible_only = False )
70
+ customers = customer_dao .get_all ()
58
71
projects = self .repository .find_all (event_ctx , ** kwargs )
59
- for project in projects :
60
- print (project .__dict__ )
72
+ active_projects = []
61
73
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
63
82
64
83
65
84
def create_dao () -> ProjectDao :
0 commit comments