feat: patch questionnaire doesn't overwrite with none
This commit is contained in:
parent
c9cd75a7ad
commit
7833386350
2 changed files with 12 additions and 3 deletions
|
|
@ -39,7 +39,7 @@ from src.organisation.schemas import OrgPostOrgRequest, OrgPatchQuestionnaireReq
|
|||
OrgPatchContactRequest, \
|
||||
OrgPostUserRequest, OrgGetUserResponse, OrgGetContactResponse, OrgGetOrgResponse, OrgPatchRootRequest, \
|
||||
OrgGetGroupResponse, OrgDeleteUserRequest, OrgDeleteOrgRequest, OrgPostOrgResponse, OrgPatchQuestionnaireResponse, \
|
||||
OrgPatchStatusResponse, OrgPostUserResponse, OrgPatchRootResponse
|
||||
OrgPatchStatusResponse, OrgPostUserResponse, OrgPatchRootResponse, Questionnaire
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/org",
|
||||
|
|
@ -131,12 +131,21 @@ async def update_questionnaire(db: db_dependency, org_model: org_model_root_clai
|
|||
The partial bool allows for submission of partially completed questionnaire and/or
|
||||
final "are you sure" check before setting the org to be in "submitted" status, awaiting admin approval.
|
||||
"""
|
||||
org_model.intake_questionnaire = request_model.intake_questionnaire.model_dump()
|
||||
update_data = request_model.intake_questionnaire.model_dump(exclude_none=True)
|
||||
questionnaire_model = Questionnaire(**org_model.intake_questionnaire)
|
||||
for key, value in update_data.items():
|
||||
if hasattr(questionnaire_model, key):
|
||||
setattr(questionnaire_model, key, value)
|
||||
else:
|
||||
if key == "partial" or key == "organisation_id":
|
||||
continue
|
||||
raise UnprocessableContentException("Invalid keys in update request")
|
||||
|
||||
# Allows for partially completed questionnaires to be saved without being submitted for review
|
||||
if not request_model.partial:
|
||||
org_model.status = "submitted"
|
||||
|
||||
org_model.intake_questionnaire = questionnaire_model.model_dump()
|
||||
db.flush()
|
||||
response = OrgPatchQuestionnaireResponse(**org_model.__dict__)
|
||||
db.commit()
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ async def test_patch_org_questionnaire_partial_success(client: AsyncClient, db_s
|
|||
assert data["name"] == "Test Org"
|
||||
assert data["intake_questionnaire"]["question_one"] == "new answer one"
|
||||
assert data["status"] == "partial"
|
||||
# assert type(data["intake_questionnaire"]["question_two"]) == str
|
||||
assert data["intake_questionnaire"]["question_two"] == "answer two"
|
||||
assert data["intake_questionnaire"]["question_three"] is None
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue