Feature/query refactoring and validations 2395

https://www.openproject.org/work_packages/2395

:exclamation: Don't forget [the related OpenProject Backlogs PR 61](https://github.com/finnlabs/openproject-backlogs/pull/61)