Delete options and answers before deleting question

This commit is contained in:
Rotimi Best
2021-09-24 23:51:44 +03:00
parent 6e24435a9f
commit 70230b3451
+5 -2
View File
@@ -213,6 +213,11 @@ export async function upsertExercise(questionnaire, exerciseId) {
if (deleted_at) { if (deleted_at) {
// Delete from server only if this question exists in the database // Delete from server only if this question exists in the database
if (!isNew(id)) { if (!isNew(id)) {
await supabase.from('option').delete().match({ question_id: id });
await supabase
.from('question_answer')
.delete()
.match({ question_id: id });
const { error } = await supabase const { error } = await supabase
.from('question') .from('question')
.delete() .delete()
@@ -222,8 +227,6 @@ export async function upsertExercise(questionnaire, exerciseId) {
console.error('Cannot delete this question', error); console.error('Cannot delete this question', error);
continue; continue;
} }
await supabase.from('option').delete().match({ question_id: id });
} }
// Skip the remaining operation so we filter out this question from the new questions array // Skip the remaining operation so we filter out this question from the new questions array