In my Nest.js project, I'm encountering a specific scenario. I have an endpoint that receives a request body, and within this endpoint, I call a service method while passing the received body as a parameter. This service method contains three conditional statements along with some business logic. However, prior to these conditionals, I need to retrieve a 'transaction' object from the database. Importantly, this 'transaction' object is also required within the conditional statements.
To improve code readability and maintainability, I intend to extract these conditional statements into three separate guards. However, this introduces a potential issue: the server would make four database requests - three times in the guards and once in the service for other business logic.
What strategies or techniques can I employ to minimize the number of database requests while still using guards to handle the conditional logic effectively?