@@ -129,6 +129,7 @@ def find_all(
129
129
130
130
if event_context .is_admin :
131
131
conditions .pop ("owner_id" )
132
+ # TODO should be removed when implementing a role-based permission module ↑
132
133
133
134
custom_params = self .generate_params (date_range )
134
135
time_entries = CosmosDBRepository .find_all (
@@ -143,7 +144,7 @@ def find_all(
143
144
projects_id = [project .project_id for project in time_entries ]
144
145
p_ids = str (tuple (projects_id )).replace ("," , "" ) if len (projects_id ) == 1 else str (tuple (projects_id ))
145
146
custom_conditions = "c.id IN {}" .format (p_ids )
146
-
147
+ # TODO this must be refactored to be used from the utils module ↑
147
148
project_dao = projects_model .create_dao ()
148
149
projects = project_dao .get_all (custom_sql_conditions = [custom_conditions ])
149
150
add_project_name_to_time_entries (time_entries , projects )
@@ -304,13 +305,7 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
304
305
event_ctx = self .create_event_context ("read-many" )
305
306
conditions .update ({"owner_id" : event_ctx .user_id })
306
307
307
- if "start_date" and "end_date" in conditions :
308
- date_range = conditions .copy ()
309
- date_range .pop ("owner_id" )
310
- conditions .pop ("start_date" )
311
- conditions .pop ("end_date" )
312
- else :
313
- date_range = self .handle_date_filter_args (args = conditions )
308
+ date_range = self .handle_date_filter_args (args = conditions )
314
309
return self .repository .find_all (event_ctx , conditions = conditions , date_range = date_range )
315
310
316
311
def get (self , id ):
@@ -383,19 +378,26 @@ def get_worked_time(self, conditions: dict = {}):
383
378
384
379
@staticmethod
385
380
def handle_date_filter_args (args : dict ) -> dict :
381
+ date_range = None
386
382
if 'month' and 'year' in args :
387
383
month = int (args .get ("month" ))
388
384
year = int (args .get ("year" ))
389
385
args .pop ('month' )
390
386
args .pop ('year' )
387
+ elif "start_date" and "end_date" in args :
388
+ date_range = args .copy ()
389
+ if "owner_id" in date_range :
390
+ date_range .pop ("owner_id" )
391
+ args .pop ("start_date" )
392
+ args .pop ("end_date" )
391
393
elif 'month' in args :
392
394
month = int (args .get ("month" ))
393
395
year = get_current_year ()
394
396
args .pop ('month' )
395
397
else :
396
398
month = get_current_month ()
397
399
year = get_current_year ()
398
- return get_date_range_of_month (year , month )
400
+ return date_range if date_range else get_date_range_of_month (year , month )
399
401
400
402
401
403
def create_dao () -> TimeEntriesDao :
0 commit comments