aboutsummaryrefslogtreecommitdiff
path: root/js/graduation-common.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/graduation-common.js')
-rw-r--r--js/graduation-common.js43
1 files changed, 27 insertions, 16 deletions
diff --git a/js/graduation-common.js b/js/graduation-common.js
index 1c68f38..52c1bd4 100644
--- a/js/graduation-common.js
+++ b/js/graduation-common.js
@@ -1,4 +1,4 @@
-import { loadFromStudentDatabase, addEntryToStudentDatabase } from "./database.js"
+import { getSubmitDb, loadFromStudentDatabase, addEntryToStudentDatabase } from "./database.js"
const LEVEL_NAMES = ["Neuling", "Entdecker", "Pionieer"];
@@ -292,31 +292,42 @@ class Observation {
}
}
-async function fetchGraduationChangesFromDb(student, type) {
- const data = await loadFromStudentDatabase(student, type);
-
+function changesFromDbEntries(entries) {
let changes = [];
- for (const e of data) {
+ for (const e of entries) {
const gradChange = GraduationChange.fromDBEntry(e);
changes.push(gradChange);
}
- return changes.flat();
+ return changes;
+}
+
+async function fetchGraduationChangesFromDb(student, type) {
+ const data = await loadFromStudentDatabase(student, type);
+ return changesFromDbEntries(data);
+}
+
+const submitEntriesPromise = async function() {
+ const db = await getSubmitDb();
+ const entries = await db.fetchEntries();
+ return changesFromDbEntries(entries);
+}();
+
+async function addSubmittedChanges(student, changes) {
+ let submitEntries = await submitEntriesPromise;
+ for (const e of submitEntries.filter( (c) => c.coach === student.name )) {
+ changes.push(e);
+ }
+ return changes;
}
async function fetchGraduationChanges(student) {
- let changes = await Promise.all([
- fetchGraduationChangesFromDb(student, "shadow"),
- fetchGraduationChangesFromDb(student, "submit"),
- ]);
- return changes.flat();
+ let changes = await fetchGraduationChangesFromDb(student, "shadow");
+ return addSubmittedChanges(student, changes);
}
async function fetchPublicGraduationChanges(student) {
- let changes = await Promise.all([
- fetchGraduationChangesFromDb(student, "public"),
- fetchGraduationChangesFromDb(student, "submit"),
- ]);
- return changes.flat();
+ let changes = await fetchGraduationChangesFromDb(student, "public");
+ return addSubmittedChanges(student, changes);
}
async function fetchGraduation(student) {