diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 67d61cd..ff66b1e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/ambv/black - rev: stable + rev: 23.1.0 hooks: - id: black language_version: python3 @@ -9,6 +9,6 @@ repos: hooks: - id: flake8 - repo: https://github.com/sqlalchemyorg/zimports/ - rev: 0.1.3 + rev: v0.6.0 hooks: - id: zimports diff --git a/src/match/controllers/create_match_controller.py b/src/match/controllers/create_match_controller.py index ad7c402..252e3c6 100644 --- a/src/match/controllers/create_match_controller.py +++ b/src/match/controllers/create_match_controller.py @@ -72,6 +72,8 @@ def process(self): match.save() user_1.person.pending_feedback = True user_2.person.pending_feedback = True + user_1.person.save() + user_2.person.save() return ( (True, "") if self._return_status diff --git a/src/survey/controllers/create_survey_controller.py b/src/survey/controllers/create_survey_controller.py index 4ea6e87..36aa70a 100644 --- a/src/survey/controllers/create_survey_controller.py +++ b/src/survey/controllers/create_survey_controller.py @@ -4,7 +4,6 @@ from api.utils import modify_attribute from api.utils import success_response from match import match_status -from match.models import Match from rest_framework import status from survey import constants from survey.models import Survey @@ -62,11 +61,28 @@ def process(self): status.HTTP_400_BAD_REQUEST, ) + # Commenting this out because iOS is sending the new match_id as the match_id, + # but we need the previous week's match id, which we can actually get the + # user's previous match using their match history. Not the most efficient, but + # a temporary fix. + # # Verify that required ids are valid - completed_match = Match.objects.filter(id=self._match_id) - if not completed_match: - return failure_response("match_id is invalid", status.HTTP_404_NOT_FOUND) - completed_match = completed_match[0] + # completed_match = Match.objects.filter(id=self._match_id) + # if not completed_match: + # return failure_response("match_id is invalid", status.HTTP_404_NOT_FOUND) + # completed_match = completed_match[0] + + prev_matches = ( + self._request.user.matches_1.all() | self._request.user.matches_1.all() + ).order_by("-created_date") + + if len(prev_matches) < 2: + return failure_response( + "User does not have enough matches", status.HTTP_400_BAD_REQUEST + ) + + # index 0 -> current match, 1 -> previous week, etc + completed_match = prev_matches[1] # Check if the submitting user has already submitted a survey survey = Survey.objects.filter(