Skip to content

Commit 37df429

Browse files
PabloPablo
authored andcommitted
fix: TT-220 make adjustments in projects query for time-entries
1 parent d43d88b commit 37df429

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

tests/time_tracker_api/projects/projects_model_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_find_all_projects_new_version(
2929
project_repository.container.query_items = query_items_mock
3030

3131
result = project_repository.find_all(
32-
event_context, ['id'], ['customer_id']
32+
event_context, {"customer_id": "1"}, ['id'], ['customer_id']
3333
)
3434
find_partition_key_value_mock.assert_called_once()
3535
assert len(result) == 1

time_tracker_api/projects/projects_model.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,17 @@ def __init__(self):
7171
def find_all(
7272
self,
7373
event_context: EventContext,
74+
conditions: dict = None,
7475
project_ids: List[str] = None,
7576
customer_ids: List[str] = None,
7677
visible_only=True,
7778
mapper: Callable = None,
7879
):
80+
params = self.generate_params(conditions) if conditions else []
81+
7982
query_builder = (
8083
CosmosDBQueryBuilder()
84+
.add_sql_where_equal_condition(conditions)
8185
.add_sql_in_condition("id", project_ids)
8286
.add_sql_in_condition("customer_id", customer_ids)
8387
.add_sql_visibility_condition(visible_only)
@@ -87,6 +91,7 @@ def find_all(
8791
tenant_id_value = self.find_partition_key_value(event_context)
8892
result = self.container.query_items(
8993
query=query_str,
94+
parameters=params,
9095
partition_key=tenant_id_value,
9196
)
9297
function_mapper = self.get_mapper_or_dict(mapper)
@@ -120,18 +125,12 @@ def get_all(
120125
]
121126

122127
conditions = conditions if conditions else {}
123-
customers_ids_conditions = [v for k, v in conditions.items()]
124-
125-
customers_ids_conditions = (
126-
customers_ids_conditions + customers_id
127-
if customers_id
128-
else customers_ids_conditions
129-
)
130128

131129
projects = self.repository.find_all(
132130
event_context=event_ctx,
131+
conditions=conditions,
133132
project_ids=project_ids,
134-
customer_ids=customers_ids_conditions,
133+
customer_ids=customers_id,
135134
)
136135

137136
add_customer_name_to_projects(projects, customers)

0 commit comments

Comments
 (0)