Description
Overview of the issue
The UI currently handles the logic for determining the status of reviews based on the responses to said review, which has a number of concerns:
- It's more inefficient to run this on the user
- Users only using the API will have to determine the review status out themselves manually
For each review, the UI currently iterates over each review response list, finds the latest response for each unique reviewer, then determines the status by seeing if they're either all approved, or if any of the latest responses are requesting changes (this will override any other approvals by different reviewers). Whilst this works, we should really be returning this information via the API.
Proposed solutuons
Adding a new property to the review model solves this, but we should be careful about this is done. We should avoid calculating this when responses are saved, as we shouldn't need to store this information in the database. Instead, we should either:
- Move the current logic from the frontend and add it to the backend service layer, and dynamically append this new status field to the review query, or
- Move the logic inside a Mongo aggregate query
This latter of the two options will be slightly more complex to implement, but should, in theory, be far more efficient.
Ultimately, the current logic remains the same, and the UI should behave exactly like it is now, with the added benefit of less confusing logic in the frontend code, and a much easier way of retrieving the state of a review.