aboutsummaryrefslogtreecommitdiff
path: root/cockpit/js/graduation-common.js
diff options
context:
space:
mode:
Diffstat (limited to 'cockpit/js/graduation-common.js')
-rw-r--r--cockpit/js/graduation-common.js41
1 files changed, 20 insertions, 21 deletions
diff --git a/cockpit/js/graduation-common.js b/cockpit/js/graduation-common.js
index 8d0e626..4716e6d 100644
--- a/cockpit/js/graduation-common.js
+++ b/cockpit/js/graduation-common.js
@@ -1,10 +1,9 @@
-import { GRADUATION_DB, GRADUATION_DB_PARAMS_MAP } from "./config.js";
-import { loadFromDatabase, writeToDatabase } from "./database.js"
+import { GRADUATION_DB_ID, GRADUATION_ACTIVITY_ID, GRADUATION_DB_PARAMS_MAP } from "./config.js";
+import { loadFromDatabase, addEntryToDatabaseActivity } from "./database.js"
class GraduationChange {
- constructor(date, time, id, name, group, change, reason, coach, json) {
+ constructor(date, id, name, group, change, reason, coach, json) {
this.date = date;
- this.time = time;
this.id = id;
this.name = name;
this.group = group;
@@ -14,28 +13,27 @@ class GraduationChange {
this.json = json;
}
+ static DB_FIELDS = ["id", "name", "group", "change", "reason", "json"];
+
static newGreenPointChange(student, reason, coach) {
- const now = new Date();
return new GraduationChange(
- now, now.toTimeString(),
+ new Date(),
student.id, student.name, student.group,
"GrĂ¼n", reason, coach, ""
);
}
static newOrangePointChange(student, reason, coach) {
- const now = new Date();
return new GraduationChange(
- now, now.toTimeString(),
+ new Date(),
student.id, student.name, student.group,
"Orange", reason, coach, ""
);
}
static newRedPointChange(student, reason, coach) {
- const now = new Date();
return new GraduationChange(
- now, now.toTimeString(),
+ new Date(),
student.id, student.name, student.group,
"Rot", reason, coach, ""
);
@@ -96,20 +94,14 @@ class Graduation {
async function fetchGraduationChanges(student) {
let params = {};
+ // The id is enough
+ params[GRADUATION_DB_PARAMS_MAP["id"]] = student.id;
- for (const key in student) {
- if (GRADUATION_DB_PARAMS_MAP[key] instanceof Function) {
- const res = GRADUATION_DB_PARAMS_MAP[key](student[key]);
- Object.assign(res, params);
- } else {
- params[GRADUATION_DB_PARAMS_MAP[key]] = student[key];
- }
- }
- const data = await loadFromDatabase(GRADUATION_DB, params);
+ const data = await loadFromDatabase(GRADUATION_DB_ID, params);
let changes = [];
for (const e of data) {
- const gradChange = new GraduationChange(e.date, e.time, e.id, e.name, e.group, e.change, e.reason, e.coach, e.json);
+ const gradChange = new GraduationChange(e.date, e.id, e.name, e.group, e.change, e.reason, e.coach, e.json);
changes.push(gradChange);
}
return changes;
@@ -121,8 +113,15 @@ async function fetchGraduation(student) {
}
async function submitGraduationChange(student, change) {
+ let params = {};
student.graduation.addChange(change);
- writeToDatabase(change);
+ for (const key of GraduationChange.DB_FIELDS) {
+ if (GRADUATION_DB_PARAMS_MAP[key]) {
+ params[GRADUATION_DB_PARAMS_MAP[key]] = change[key];
+ }
+ }
+
+ addEntryToDatabaseActivity(GRADUATION_ACTIVITY_ID, params);
}
export {