mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 11:58:13 +00:00
commit
cb7be6e70b
2 changed files with 64 additions and 4 deletions
|
|
@ -4,6 +4,7 @@ import {
|
|||
ActivityResponse,
|
||||
BadgesResponse,
|
||||
BehaviourResponse,
|
||||
DetentionsResponse,
|
||||
GetActivityOptions,
|
||||
GetBehaviourOptions,
|
||||
GetHomeworkOptions,
|
||||
|
|
@ -119,7 +120,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(),
|
||||
|
|
@ -137,7 +138,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(
|
||||
|
|
@ -158,6 +159,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(
|
||||
|
|
@ -166,12 +168,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(/ /g, "");
|
||||
data[i].description = data[i].description.trim();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
/**
|
||||
|
|
@ -202,4 +208,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",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
44
src/types.ts
44
src/types.ts
|
|
@ -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>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue