blob: 663493a23e63e56688443b8e5ee3b232938d21a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import { getGraduationDb } from "./database-ENV.ts";
import { Graduation, GraduationChange } from "./graduation-common.ts";
import type { Student } from "./student-common.ts";
const _graduationChangesPromise = (async function () {
const db = await getGraduationDb();
let changes = new Map();
let entries = await db.fetchEntries();
for (const e of entries) {
const gradChange = GraduationChange.fromDBEntry(e);
const studentChanges = changes.get(gradChange.studentId);
if (studentChanges === null) {
changes.set(gradChange.studentId, [gradChange]);
} else {
studentChanges.push(gradChange);
}
}
return changes;
})();
const graduations: Map<number, Graduation> = new Map();
export async function fetchGraduation(student: Student): Promise<Graduation> {
if (!graduations.has(student.id)) {
const studentChanges = (await _graduationChangesPromise).get(student.id) ?? [];
const graduation = Graduation.from(student, studentChanges);
graduations.set(student.id, graduation);
return graduation;
}
return graduations.get(student.id)!;
}
export {
LEVEL_NAMES,
GraduationChange,
Graduation,
submitGraduationChange,
submitObservation,
OBSERVATION_TYPES,
Observation,
ObservationPeriod,
} from "./graduation-common.ts";
|