Skip to content

Commit

Permalink
Hot fix WAI-939: survey submissions with empty answers blocking sync (b…
Browse files Browse the repository at this point in the history
  • Loading branch information
edmofro authored and Edwin committed Sep 9, 2021
1 parent 8b8ce14 commit eb0ede5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const processQuestions = async (dispatch, getState, database, userId, questions)
const answers = getAnswers(getState());
for (const question of questions) {
const answer = answers[question.id];
if (answer === undefined) {
if (answer === undefined || answer === null || answer === '') {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/meditrak-app/ios/TupaiaMediTrak/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.11.113</string>
<string>1.11.114</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>113</string>
<string>114</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
2 changes: 1 addition & 1 deletion packages/meditrak-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tupaia/meditrak-app",
"version": "1.11.113",
"version": "1.11.114",
"private": true,
"description": "Android and iOS app for surveying medical facilities",
"repository": {
Expand Down
7 changes: 5 additions & 2 deletions packages/meditrak-server/src/apiV2/postChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ const requiresSurveyResponseTranslation = (
const answerTranslatorFields = Object.keys(answerTranslators);
const { answers } = surveyResponseObject;
if (Array.isArray(answers)) {
return answers.some(answer =>
Object.keys(answer).some(field => answerTranslatorFields.includes(field)),
return answers.some(
answer =>
answer.body === '' ||
Object.keys(answer).some(field => answerTranslatorFields.includes(field)),
);
}

Expand All @@ -200,6 +202,7 @@ const constructSurveyResponseTranslators = models => ({
user_email: userEmail => translateUserEmailToIdAndAssessorName(models.user, userEmail),
entity_code: entityCode => translateEntityCodeToId(models.entity, entityCode),
survey_code: surveyCode => translateSurveyCodeToId(models.survey, surveyCode),
answers: answers => ({ answers: answers.filter(a => a.body !== '') }), // remove any empty answers
});

const constructAnswerTranslators = models => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export const translateObjectFields = async (object, objectTranslators) => {
Object.entries(object).map(async ([field, value]) => {
if (objectTranslators[field]) {
const newFields = await objectTranslators[field](value);
Object.entries(newFields).forEach(([newField, newValue]) => (object[newField] = newValue));
delete object[field];
Object.entries(newFields).forEach(([newField, newValue]) => (object[newField] = newValue));
}
}),
);
Expand Down

0 comments on commit eb0ede5

Please sign in to comment.