From 62e667a4e8b989021fb9e15a0ca1258e880a92e0 Mon Sep 17 00:00:00 2001 From: ZelrDev Date: Sun, 6 Feb 2022 10:32:35 +0000 Subject: [PATCH] Make some types better, add get detentions --- src/client.ts | 22 ++++++++++++++++++++-- src/types.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/client.ts b/src/client.ts index 1e0f6af..baef725 100644 --- a/src/client.ts +++ b/src/client.ts @@ -4,6 +4,7 @@ import { ActivityResponse, BadgesResponse, BehaviourResponse, + DetentionsResponse, GetActivityOptions, GetBehaviourOptions, GetHomeworkOptions, @@ -112,7 +113,7 @@ export class ClasschartsClient { */ async getActivity(options?: GetActivityOptions): Promise { 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 { 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 = 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(/ /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 { + return await this.makeAuthedRequest( + API_BASE + "/detentions/" + this.studentId, + { + method: "GET", + } + ); + } } diff --git a/src/types.ts b/src/types.ts index 44343a0..49787bb 100644 --- a/src/types.ts +++ b/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"; @@ -179,4 +180,45 @@ export interface Badge { pupil_badges: Array; icon_url: string; } -export type BadgesResponse = Array; \ No newline at end of file +export type BadgesResponse = Array; + +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; \ No newline at end of file