This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
sigaa-bond-factory.ts
executable file
·89 lines (82 loc) · 2.45 KB
/
sigaa-bond-factory.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { ActivityFactory } from '@activity/sigaa-activity-factory';
import { CourseFactory } from '@courses/sigaa-course-student-factory';
import { Parser } from '@helpers/sigaa-parser';
import { HTTP } from '@session/sigaa-http';
import { HTTPFactory } from '@session/sigaa-http-factory';
import { SigaaStudentBond, StudentBond } from './sigaa-student-bond';
import { SigaaTeacherBond, TeacherBond } from './sigaa-teacher-bond';
/**
* Union of all bonds (StudentBont and TeacherBond).
* @category Internal
*/
export type BondType = StudentBond | TeacherBond;
/**
* Abstraction to represent a class that creates bond instances.\
* @category Internal
*/
export interface BondFactory {
/**
* Creates a student program instance.
*
* @param registration It is the student registration code, in IFSC it is called "matrícula".
* @param program It's the name of the student program, in IFSC it is called "curso".
* @param bondSwitchUrl If the user has more than one bond, the bond link will be used to change the bond
*/
createStudentBond(
registration: string,
program: string,
bondSwitchUrl: URL | null
): StudentBond;
/**
* Creates a teacher bond instance.
*/
createTeacherBond(): TeacherBond;
}
/**
* Class to implements BondFactory.
*
* Serves to create bond instances.
* @category Internal
*/
export class SigaaBondFactory implements BondFactory {
constructor(
private httpFactory: HTTPFactory,
private parser: Parser,
private courseFactory: CourseFactory,
private activityFactory: ActivityFactory
) {}
/**
* Creates a student program instance.
*
* @param registration It is the student registration code
* @param program It's the name of the student program, in Portuguese it is called "curso".
* @param bondSwitchUrl If the user has more than one bond, the bond link will be used to change the bond
*/
createStudentBond(
registration: string,
program: string,
bondSwitchUrl: URL | null
): StudentBond {
let http: HTTP;
if (bondSwitchUrl) {
http = this.httpFactory.createHttpWithBond(bondSwitchUrl);
} else {
http = this.httpFactory.createHttp();
}
return new SigaaStudentBond(
http,
this.parser,
this.courseFactory,
this.activityFactory,
program,
registration,
bondSwitchUrl
);
}
/**
* Creates a teacher bond instance.
*/
createTeacherBond(): TeacherBond {
return new SigaaTeacherBond();
}
}