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",
}
);
}
}

View file

@ -107,6 +107,7 @@ export interface Homework {
title: string;
meta_title: string;
description: string;
description_raw: string,
issue_date: string;
due_date: string;
completion_time_unit: string;
@ -114,7 +115,7 @@ export interface Homework {
publish_time: string;
status: {
id: number;
state: any | null;
state: "not_completed" | "late" | "completed" | null;
mark: any | null;
mark_relative: number;
ticked: "yes" | "no";
@ -180,3 +181,44 @@ export interface Badge {
icon_url: string;
}
export type BadgesResponse = Array<Badge>;
export interface Detention {
id: number;
attended: "yes" | "no" | "upscaled" | "pending";
date: string | null;
length: number | null;
location: string | null;
notes: string | null;
time: string | null;
pupil: {
id: number;
first_name: string;
last_name: string;
school: {
opt_notes_names: "yes" | "no";
opt_notes_comments: "yes" | "no";
opt_notes_comments_pupils: "yes" | "no";
};
};
lesson: {
id: number;
name: string;
subject: {
id: number;
name: string;
};
};
lesson_pupil_behaviour: {
reason: string;
};
teacher: {
id: number;
first_name: string;
last_name: string;
title: string;
};
detention_type: {
name: string;
};
}
export type DetentionsResponse = Array<Detention>;