diff --git a/aleksis/apps/alsijil/assets/components/alsijil/PersonalNotes.js b/aleksis/apps/alsijil/assets/components/alsijil/PersonalNotes.js index 37b00a7f13ceaf227ed03bae3125740be8ff2494..49fa3d527c0382d2b07132ca26b3b28af33b020a 100644 --- a/aleksis/apps/alsijil/assets/components/alsijil/PersonalNotes.js +++ b/aleksis/apps/alsijil/assets/components/alsijil/PersonalNotes.js @@ -1,3 +1,5 @@ +import gql from 'graphql-tag'; + const ID_NO_PERSON = null; export default { @@ -65,6 +67,73 @@ export default { return } + // We save the user input in case of an error + const variables = { + "personId": this.editedPersonID, + "late": this.editedTardiness, + "absent": this.editedAbsent, + "excused": this.editedExcused, + "excuseType": this.editedExcuseType, + "extraMarks": this.editedExtraMarks, + "remarks": this.editedRemarks, + "lessonDocumentation": this.lessonDocumentationId, + } + + console.log(variables) + + // Call to the graphql mutation + this.$apollo.mutate({ + // Query + mutation: gql`mutation updateOrCreatePersonalNote( + $personId: ID!, + $lessonDocumentation: ID!, + $late: Int, + $absent: Boolean, + $excused: Boolean, + $excuseType: ID, + $extraMarks: [ID], + $remarks: String + ) { + updateOrCreatePersonalNote(personId: $personId, + lessonDocumentation: $lessonDocumentation, + late: $late, + absent: $absent, + excused: $excused, + excuseType: $excuseType, + extraMarks: $extraMarks, + remarks: $remarks + ) { + personalNote { + id + person { + id + fullName + } + remarks + absent + excused + excuseType { + id + } + extraMarks { + id + } + } + } + } + `, + // Parameters + variables: variables, + }).then((data) => { + // Result + console.log(data) + // FIXME: check if data changed (?), display success message + }).catch((error) => { + // Error + console.error(error) + // FIXME: Notify the user about the error, maybe retry + }) + if (this.newPersonalNote) { this.personalNotes.push({ person: {