def update_user_survey_by_id(_id): """ Update/replace existing survey by _id """ survey = Survey() content = request.get_json(silent=True, force=True) old = 'NO OLD SURVEY FOUND!' try: old = survey.getByID(_id).serialize() return jsonify(success=bool( survey.updateByUniqueID(_id, content['survey'], content['tags'], content['ongoing']))) except ValueError as error: raise MethodNotAllowed(error.message) except BadValueException as error: raise MethodNotAllowed(error.message) except SurveyNotFound as error: raise SurveyNotFound(_id) finally: add_to_audit_log( 'update_user_survey_by_id', survey_id=_id, new=content, old=old, )
def delete_survey_by_id(_id): """ Delete existing survey by _id """ survey = Survey() old = 'NO OLD SURVEY FOUND!' try: old = survey.getByID(_id).serialize() return jsonify(success=bool(survey.deleteByUniqueID(_id))) except ValueError as error: raise MethodNotAllowed(error.message) except BadValueException as error: raise MethodNotAllowed(error.message) except SurveyNotFound as error: raise SurveyNotFound(_id) finally: add_to_audit_log( 'delete_survey_by_id', survey_id=_id, old=old, )