|
4 | 4 | from api.utils import modify_attribute |
5 | 5 | from api.utils import success_response |
6 | 6 | from match import match_status |
7 | | -from match.models import Match |
8 | 7 | from rest_framework import status |
9 | 8 | from survey import constants |
10 | 9 | from survey.models import Survey |
@@ -62,11 +61,28 @@ def process(self): |
62 | 61 | status.HTTP_400_BAD_REQUEST, |
63 | 62 | ) |
64 | 63 |
|
| 64 | + # Commenting this out because iOS is sending the new match_id as the match_id, |
| 65 | + # but we need the previous week's match id, which we can actually get the |
| 66 | + # user's previous match using their match history. Not the most efficient, but |
| 67 | + # a temporary fix. |
| 68 | + # |
65 | 69 | # Verify that required ids are valid |
66 | | - completed_match = Match.objects.filter(id=self._match_id) |
67 | | - if not completed_match: |
68 | | - return failure_response("match_id is invalid", status.HTTP_404_NOT_FOUND) |
69 | | - completed_match = completed_match[0] |
| 70 | + # completed_match = Match.objects.filter(id=self._match_id) |
| 71 | + # if not completed_match: |
| 72 | + # return failure_response("match_id is invalid", status.HTTP_404_NOT_FOUND) |
| 73 | + # completed_match = completed_match[0] |
| 74 | + |
| 75 | + prev_matches = ( |
| 76 | + self._request.user.matches_1.all() | self._request.user.matches_1.all() |
| 77 | + ).order_by("-created_date") |
| 78 | + |
| 79 | + if len(prev_matches) < 2: |
| 80 | + return failure_response( |
| 81 | + "User does not have enough matches", status.HTTP_400_BAD_REQUEST |
| 82 | + ) |
| 83 | + |
| 84 | + # index 0 -> current match, 1 -> previous week, etc |
| 85 | + completed_match = prev_matches[1] |
70 | 86 |
|
71 | 87 | # Check if the submitting user has already submitted a survey |
72 | 88 | survey = Survey.objects.filter( |
|
0 commit comments