Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: TT-220 make adjustments in projects query for time-entries
  • Loading branch information
Pablo authored and Pablo committed May 17, 2021
commit 37df4290592a93bdf9a0916609cf6eef86fed479
2 changes: 1 addition & 1 deletion tests/time_tracker_api/projects/projects_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_find_all_projects_new_version(
project_repository.container.query_items = query_items_mock

result = project_repository.find_all(
event_context, ['id'], ['customer_id']
event_context, {"customer_id": "1"}, ['id'], ['customer_id']
)
find_partition_key_value_mock.assert_called_once()
assert len(result) == 1
Expand Down
15 changes: 7 additions & 8 deletions time_tracker_api/projects/projects_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ def __init__(self):
def find_all(
self,
event_context: EventContext,
conditions: dict = None,
project_ids: List[str] = None,
customer_ids: List[str] = None,
visible_only=True,
mapper: Callable = None,
):
params = self.generate_params(conditions) if conditions else []

query_builder = (
CosmosDBQueryBuilder()
.add_sql_where_equal_condition(conditions)
.add_sql_in_condition("id", project_ids)
.add_sql_in_condition("customer_id", customer_ids)
.add_sql_visibility_condition(visible_only)
Expand All @@ -87,6 +91,7 @@ def find_all(
tenant_id_value = self.find_partition_key_value(event_context)
result = self.container.query_items(
query=query_str,
parameters=params,
partition_key=tenant_id_value,
)
function_mapper = self.get_mapper_or_dict(mapper)
Expand Down Expand Up @@ -120,18 +125,12 @@ def get_all(
]

conditions = conditions if conditions else {}
customers_ids_conditions = [v for k, v in conditions.items()]

customers_ids_conditions = (
customers_ids_conditions + customers_id
if customers_id
else customers_ids_conditions
)

projects = self.repository.find_all(
event_context=event_ctx,
conditions=conditions,
project_ids=project_ids,
customer_ids=customers_ids_conditions,
customer_ids=customers_id,
)

add_customer_name_to_projects(projects, customers)
Expand Down