1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 11:58:13 +00:00

Make some types better, add get detentions

This commit is contained in:
ZelrDev 2022-02-06 10:32:35 +00:00
parent 02eac2ce7e
commit 62e667a4e8
2 changed files with 64 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import {
ActivityResponse,
BadgesResponse,
BehaviourResponse,
DetentionsResponse,
GetActivityOptions,
GetBehaviourOptions,
GetHomeworkOptions,
@ -112,7 +113,7 @@ export class ClasschartsClient {
*/
async getActivity(options?: GetActivityOptions): Promise<ActivityResponse> {
const params = new URLSearchParams();
options?.from && params.append("form", options?.from);
options?.from && params.append("from", options?.from);
options?.to && params.append("to", options?.to);
return this.makeAuthedRequest(
API_BASE + "/activity/" + this.sessionId + "?" + params.toString(),
@ -130,7 +131,7 @@ export class ClasschartsClient {
options?: GetBehaviourOptions
): Promise<BehaviourResponse> {
const params = new URLSearchParams();
options?.from && params.append("form", options?.from);
options?.from && params.append("from", options?.from);
options?.to && params.append("to", options?.to);
options?.last_id && params.append("last_id", options?.last_id);
return await this.makeAuthedRequest(
@ -151,6 +152,7 @@ export class ClasschartsClient {
const params = new URLSearchParams();
if (options?.displayDate)
params.append("display_date", String(options?.displayDate));
options?.fromDate && params.append("from", String(options?.fromDate));
options?.toDate && params.append("to", String(options?.toDate));
const data: Array<Homework> = await this.makeAuthedRequest(
@ -159,12 +161,16 @@ export class ClasschartsClient {
method: "GET",
}
);
for (let i = 0; i < data.length; i++) {
data[i].description_raw = data[i].description;
// homework.lesson.replace(/\\/g, '')
data[i].description = data[i].description.replace(/(<([^>]+)>)/gi, "");
data[i].description = data[i].description.replace(/&nbsp;/g, "");
data[i].description = data[i].description.trim();
}
return data;
}
/**
@ -195,4 +201,16 @@ export class ClasschartsClient {
}
);
}
/**
* Gets the logged in student's detentions
* @returns Array of detentions
*/
async getDetentions(): Promise<DetentionsResponse> {
return await this.makeAuthedRequest(
API_BASE + "/detentions/" + this.studentId,
{
method: "GET",
}
);
}
}