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, 39 insertions, 4 deletions
diff --git a/js/graduation-common.js b/js/graduation-common.js
index 94fd0d6..3ab1fdd 100644
--- a/js/graduation-common.js
+++ b/js/graduation-common.js
@@ -19,6 +19,26 @@ class GraduationChange {
].includes(this.change);
}
+ publicDBFields () {
+ return {
+ "change": this.change,
+ };
+ }
+
+ dbFields () {
+ return {
+ "change": this.change,
+ "reason": this.reason,
+ "context": this.context,
+ };
+ }
+
+ static fromDBEntry(e) {
+ const {date, coach, json} = e;
+ const change = JSON.parse(json);
+ return new GraduationChange(new Date(date), change.change, change.reason, coach, change.context);
+ }
+
static newGreenPointChange(reason, coach) {
return new GraduationChange(new Date(), "GrĂ¼n", reason, coach, "");
}
@@ -178,8 +198,8 @@ class Observation {
}
}
-async function fetchGraduationChanges(student) {
- const data = await loadFromStudentDatabase(student, "shadow");
+async function fetchGraduationChangesFromDb(student, type) {
+ const data = await loadFromStudentDatabase(student, type);
let changes = [];
for (const e of data) {
@@ -189,11 +209,24 @@ async function fetchGraduationChanges(student) {
return changes;
}
+async function fetchGraduationChanges(student) {
+ return fetchGraduationChangesFromDb(student, "shadow");
+}
+
+async function fetchPublicGraduationChanges(student) {
+ return fetchGraduationChangesFromDb(student, "public");
+}
+
async function fetchGraduation(student) {
const changes = await fetchGraduationChanges(student);
return Graduation.from(student, changes);
}
+async function fetchPublicGraduation(student) {
+ const changes = await fetchPublicGraduationChanges(student);
+ return Graduation.from(student, changes);
+}
+
async function submitGraduationChange(student, change) {
student.graduation.addChange(change);
@@ -203,12 +236,12 @@ async function submitGraduationChange(student, change) {
if (change.isPublic()) {
promises.push(
// TODO(muhq): strip non public fields from changes
- addEntryToStudentDatabase(student, "public", JSON.stringify(change))
+ addEntryToStudentDatabase(student, "public", JSON.stringify(change.publicDBFields()))
);
}
promises.push(
- addEntryToStudentDatabase(student, "shadow", JSON.stringify(change))
+ addEntryToStudentDatabase(student, "shadow", JSON.stringify(change.dbFields()))
);
await Promise.all(promises);
@@ -224,7 +257,9 @@ export {
GraduationChange,
Graduation,
fetchGraduation,
+ fetchPublicGraduation,
fetchGraduationChanges,
+ fetchPublicGraduationChanges,
submitGraduationChange,
submitObservation,