-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetTimeline.ts
42 lines (36 loc) · 1.5 KB
/
getTimeline.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
import {Session} from "~/session";
import bodyToString from "~/utils/body";
import {studTlElem, studCommonTlResData, studTlRes, studCommonTlRes} from "~/types/v3";
import {timelineRequestData} from "~/types/v3/requests";
import {decodeString} from "~/utils/base64";
class GetTimeline {
session: Session;
constructor(session: Session) {
this.session = session;
}
async fetch(): Promise<Array<studTlElem>> {
const url = `/eleves/${this.session.student.id}/timeline.awp`;
const data = {} as timelineRequestData;
return await this.session.request.get(url, bodyToString(data)).then((response: studTlRes) => response.data as Array<studTlElem>);
}
async fetchCommonTimeline(): Promise<studCommonTlResData> {
const url = `/E/${this.session.student.id}/timelineAccueilCommun.awp`;
const data = {} as timelineRequestData;
return await this.session.request.get(url, bodyToString(data)).then((response: studCommonTlRes) => {
if (response.code == 200) {
const data = response.data as studCommonTlResData;
data.evenements.forEach(event => {
event.description = decodeString(event.description);
});
data.postits.forEach(postit => {
postit.contenu = decodeString(postit.contenu);
});
return data;
}
return response.data as studCommonTlResData;
});
}
}
export {
GetTimeline
};