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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import EventInfo from "./EventInfo";
import { labStore } from "../stores";
import { get } from "svelte/store"
interface PeerTeacherSerializeInfo {
id: number,
firstname: string,
lastname: string,
events: {
days: string,
start: number,
end: number
}[],
labs: number[],
email: string,
}
export default class PeerTeacher {
id: number;
firstname: string;
lastname: string;
events: EventInfo[];
labs: Set<number>;
email: string;
constructor(id: number | string, firstname: string, lastname: string, email: string) {
if (typeof id === "string") {
id = parseInt(id, 10);
}
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
this.events = [];
this.labs = new Set();
this.email = email;
}
static fromJSON({ id, firstname, lastname, events, labs, email }: PeerTeacherSerializeInfo) {
const pt = new PeerTeacher(id, firstname, lastname, email);
pt.events = events.map(e => EventInfo.fromJSON(e));
pt.labs = new Set(labs);
return pt;
}
conflictsWith(event: EventInfo) {
const all_labs = get(labStore);
const lab_events: EventInfo[] = [...this.labs.values()].flatMap((lab_id) => {
const lab = all_labs.get(lab_id);
return lab != undefined ? lab.event : [];
})
return lab_events.some((e) => e.conflictsWith(event)) ||
this.events.some(item => item.conflictsWith(event));
}
get name(): string {
return `${this.firstname} ${this.lastname}`;
}
get lab_hours(): number {
const all_labs = get(labStore);
let total_hours = 0;
this.labs.forEach((lab_id) => {
total_hours += all_labs.get(lab_id)!.pay_hours;
})
return total_hours;
}
}
|