Skip to content

Commit 4901914

Browse files
committed
Update survey logic to capture previous match - not current match
1 parent 172de14 commit 4901914

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/survey/controllers/create_survey_controller.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from api.utils import modify_attribute
55
from api.utils import success_response
66
from match import match_status
7-
from match.models import Match
87
from rest_framework import status
98
from survey import constants
109
from survey.models import Survey
@@ -62,11 +61,28 @@ def process(self):
6261
status.HTTP_400_BAD_REQUEST,
6362
)
6463

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+
#
6569
# 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]
7086

7187
# Check if the submitting user has already submitted a survey
7288
survey = Survey.objects.filter(

0 commit comments

Comments
 (0)