diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-07-05 19:16:51 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-07-05 19:16:51 +0200 |
| commit | fdd9a4aba9929ee21cb796b6696e64e96505447a (patch) | |
| tree | 8414f9a065c51dfec3370c9dcc99e050738106bb /js/graduation-common.js | |
| parent | c250201362c64ff4a6b1e9d077d938d771d55205 (diff) | |
| download | bycs-sol-fdd9a4aba9929ee21cb796b6696e64e96505447a.tar.gz bycs-sol-fdd9a4aba9929ee21cb796b6696e64e96505447a.zip | |
database: fix DB discovery and define public graduation fields
Diffstat (limited to 'js/graduation-common.js')
| -rw-r--r-- | js/graduation-common.js | 43 |
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, |
