Skip to content
Snippets Groups Projects
Commit be37ac4a authored by Julian's avatar Julian
Browse files

Update sendToServer to accept extramarks as well

parent 5c373791
No related branches found
No related tags found
1 merge request!400Resolve "Extra marks also in person multiple select in lesson dialog"
/**
* Mixin to provide shared functionality needed to send updated participation data to the server
*/
import { createPersonalNotes } from "../personal_notes/personal_notes.graphql";
import { updateParticipationStatuses } from "./participationStatus.graphql";
import mutateMixin from "aleksis.core/mixins/mutateMixin.js";
......@@ -18,6 +19,10 @@ export default {
fieldValue = {
tardiness: value,
};
} else if (field === "extraMark") {
// Too much different logic → own method
this.addExtraMarks(participations, value);
return;
} else {
console.error(`Wrong field '${field}' for sendToServer`);
return;
......@@ -50,5 +55,39 @@ export default {
},
);
},
addExtraMarks(participations, extraMarkId) {
// Get all participation statuses without this extra mark and get the respective person ids
const participants = participations.filter(
participation => !participation.notesWithExtraMark.some(note => note.extraMark.id === extraMarkId)
).map(participation => participation.person.id)
// CREATE new personal note
this.mutate(
createPersonalNotes,
{
input: participants.map(person => (
{
documentation: this.documentation.id,
person: person,
extraMark: extraMarkId,
}
)),
},
(storedDocumentations, incomingPersonalNotes) => {
const documentation = storedDocumentations.find(
(doc) => doc.id === this.documentation.id,
);
incomingPersonalNotes.forEach((note, index) => {
const participationStatus = documentation.participations.find(
(part) => part.person.id === participants[index],
);
participationStatus.notesWithExtraMark.push(note);
});
return storedDocumentations;
},
);
}
},
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment