Refactor to reflect db structure changes

This commit is contained in:
2022-10-25 22:42:38 +02:00
parent cc6e51d31e
commit ff9ebef36c
2 changed files with 8 additions and 12 deletions

View File

@@ -46,7 +46,7 @@
</template>
<script>
import { doc, updateDoc, arrayUnion } from 'firebase/firestore'
import { collection, addDoc } from 'firebase/firestore'
// We use vee-validate@3 for form validation.
// https://vee-validate.logaretm.com/v3/guide/basics.html
import { ValidationProvider, ValidationObserver, extend } from 'vee-validate'
@@ -86,11 +86,9 @@ export default {
status: 'neu'
}
// Atomically add the new question to the "geschlossen" (fragen/{kursID}/geschlossen) array field.
const questionsRef = doc(this.$db, 'fragen', this.$store.state.selectedCourse)
updateDoc(questionsRef, {
geschlossen: arrayUnion(q) // Ref: https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array
}).then((empty) => {
// Add a new document with a generated id.
addDoc(collection(this.$db, `kurse/${this.$store.state.selectedCourse}/fragenGeschlossen`), q)
.then((docRef) => {
// Successfully added new question to database
this.$toast({ content: 'Deine Frage wurde eingereicht!', color: 'success' })
})