aboutsummaryrefslogtreecommitdiff
path: root/src/models/PeerTeacher.ts
blob: 4020a0028990afe4be75f05e04dcb85d2141a9fe (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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[],
}

export default class PeerTeacher {
    id: number;
    firstname: string;
    lastname: string;
    events: EventInfo[];
    labs: Set<number>;

    constructor(id: number | string, firstname: string, lastname: string) {
        if (typeof id === "string") {
            id = parseInt(id, 10);
        }

        this.id = id;
        this.firstname = firstname;
        this.lastname = lastname;
        this.events = [];
        this.labs = new Set();
    }

    static fromJSON({ id, firstname, lastname, events, labs }: PeerTeacherSerializeInfo) {
        const pt = new PeerTeacher(id, firstname, lastname);
        pt.events = events.map(e => EventInfo.fromJSON(e));
        pt.labs = new Set(labs);
        return pt;
    }

    conflictsWith(event: EventInfo) {
        return 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;
    }

}