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

chore: syntax & biome.js changes

This commit is contained in:
James Cook 2024-01-10 10:57:33 +00:00
parent 790a5a6aa6
commit a64fd6a718
8 changed files with 67 additions and 42 deletions

View file

@ -2,10 +2,7 @@ name: test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:

View file

@ -1,11 +1,7 @@
name: test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test-deno:

View file

@ -6,7 +6,21 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true
"recommended": true,
"complexity": {
"noExcessiveCognitiveComplexity": "warn"
},
"correctness": {
"noUnusedVariables": "warn"
},
"style": {
"useBlockStatements": "warn",
"useShorthandArrayType": "warn",
"useShorthandAssign": "warn"
},
"suspicious": {
"noApproximativeNumericConstant": "error"
}
}
},
"files": {

View file

@ -1,7 +1,9 @@
// This dependancy cannot be moved to dev_deps.ts since dnt complains about a top-level await
import { build, emptyDir } from "https://deno.land/x/dnt@0.39.0/mod.ts";
if (!Deno.args[0]) throw new Error("No version specified");
if (!Deno.args[0]) {
throw new Error("No version specified");
}
await emptyDir("./npm");

View file

@ -22,7 +22,7 @@ import { PING_INTERVAL } from "../utils/consts.ts";
/**
* Shared client for both parent and student. This is not exported and should not be used directly
*/
export class BaseClient {
export abstract class BaseClient {
/**
* @property studentId Currently selected student ID
*/
@ -30,7 +30,7 @@ export class BaseClient {
/**
* @property authCookies Cookies used for authentication (set during login and can be empty)
*/
public authCookies: Array<string>;
public authCookies: string[];
/**
* @property sessionId Session ID used for authentication
*/
@ -50,6 +50,8 @@ export class BaseClient {
this.authCookies = [];
this.API_BASE = API_BASE;
}
abstract login(): Promise<void>;
/**
* Revalidates the session ID.
*
@ -82,9 +84,11 @@ export class BaseClient {
public async makeAuthedRequest(
path: string,
fetchOptions: RequestInit,
options: { revalidateToken?: boolean } = { revalidateToken: true },
options: { revalidateToken?: boolean; } = { revalidateToken: true },
) {
if (!this.sessionId) throw new Error("No session ID");
if (!this.sessionId) {
throw new Error("No session ID");
}
if (typeof options?.revalidateToken === "undefined") {
options.revalidateToken = true;
}
@ -226,7 +230,9 @@ export class BaseClient {
* @returns Array of lessons
*/
async getLessons(options: GetLessonsOptions): Promise<LessonsResponse> {
if (!options?.date) throw new Error("No date specified");
if (!options?.date) {
throw new Error("No date specified");
}
const params = new URLSearchParams();
params.append("date", String(options?.date));
return await this.makeAuthedRequest(

View file

@ -25,8 +25,12 @@ export class ParentClient extends BaseClient {
* Authenticates with ClassCharts
*/
async login(): Promise<void> {
if (!this.email) throw new Error("Email not provided");
if (!this.password) throw new Error("Password not provided");
if (!this.email) {
throw new Error("Email not provided");
}
if (!this.password) {
throw new Error("Password not provided");
}
const formData = new URLSearchParams();
formData.append("_method", "POST");
formData.append("email", this.email);
@ -57,7 +61,9 @@ export class ParentClient extends BaseClient {
);
this.sessionId = sessionID.session_id;
this.pupils = await this.getPupils();
if (!this.pupils) throw new Error("Account has no pupils attached");
if (!this.pupils) {
throw new Error("Account has no pupils attached");
}
this.studentId = this.pupils[0].id;
}
/**
@ -77,7 +83,9 @@ export class ParentClient extends BaseClient {
* @see getPupils
*/
selectPupil(pupilId: number) {
if (!pupilId) throw new Error("No pupil ID specified");
if (!pupilId) {
throw new Error("No pupil ID specified");
}
const pupils = this.pupils;
for (let i = 0; i < pupils.length; i++) {
const pupil = pupils[i];

View file

@ -35,7 +35,9 @@ export class StudentClient extends BaseClient {
* Authenticates with ClassCharts
*/
async login(): Promise<void> {
if (!this.studentCode) throw new Error("Student Code not provided");
if (!this.studentCode) {
throw new Error("Student Code not provided");
}
const formData = new URLSearchParams();
formData.append("_method", "POST");
formData.append("code", this.studentCode.toUpperCase());

View file

@ -77,13 +77,13 @@ export interface BehaviourTimelinePoint {
end: string;
}
export interface BehaviourResponseData {
timeline: Array<BehaviourTimelinePoint>;
timeline: BehaviourTimelinePoint[];
positive_reasons: Record<string, number>;
negative_reasons: Record<string, number>;
other_positive: Array<string>;
other_negative: Array<string>;
other_positive_count: Array<Record<string, number>>;
other_negative_count: Array<Record<string, number>>;
other_positive: string[];
other_negative: string[];
other_positive_count: Record<string, number>[];
other_negative_count: Record<string, number>[];
}
export interface BehaviourResponseMeta {
start_date: string;
@ -134,7 +134,7 @@ export interface ActivityPoint {
detention_location: string | null;
detention_type: string | null;
}
export type ActivityResponseData = Array<ActivityPoint>;
export type ActivityResponseData = ActivityPoint[];
interface ActivityResponseMeta {
start_date: string;
end_date: string;
@ -194,13 +194,13 @@ export interface Homework {
allow_attachments: boolean;
first_seen_date: string | null;
last_seen_date: string | null;
attachments: Array<unknown>;
attachments: unknown[];
has_feedback: boolean;
};
validated_links: Array<unknown>;
validated_attachments: Array<ValidatedHomeworkAttachment>;
validated_links: unknown[];
validated_attachments: ValidatedHomeworkAttachment[];
}
export type HomeworksResponseData = Array<Homework>;
export type HomeworksResponseData = Homework[];
export interface HomeworksResponseMeta {
start_date: string;
end_date: string;
@ -286,10 +286,10 @@ export interface Badge {
icon: string;
colour: string;
created_date: string;
pupil_badges: Array<PupilEvent>;
pupil_badges: PupilEvent[];
icon_url: string;
}
export type BadgesResponseData = Array<Badge>;
export type BadgesResponseData = Badge[];
export type BadgesResponseMeta = [];
export type BadgesResponse = ClassChartsResponse<
BadgesResponseData,
@ -336,7 +336,7 @@ export interface Detention {
};
}
export type DetentionsData = Array<Detention>;
export type DetentionsData = Detention[];
export interface DetentionsMeta {
detention_alias_plural: string;
@ -357,11 +357,11 @@ export interface Announcement {
sticky: "yes" | "no";
state: string | null;
timestamp: string;
attachments: Array<{
attachments: {
filename: string;
url: string;
}>;
for_pupils: Array<unknown>;
}[];
for_pupils: unknown[];
comment_visibility: string;
allow_comments: "yes" | "no";
allow_reactions: "yes" | "no";
@ -370,11 +370,11 @@ export interface Announcement {
requires_consent: "yes" | "no";
can_change_consent: boolean;
consent: unknown | null;
pupil_consents: Array<unknown>;
pupil_consents: unknown[];
}
export type AnnouncementsResponse = ClassChartsResponse<
Array<Announcement>,
Announcement[],
[]
>;
@ -397,7 +397,7 @@ export interface Pupil extends Student {
announcements_count: number;
messages_count: number;
}
export type GetPupilsResponse = Array<Pupil>;
export type GetPupilsResponse = Pupil[];
export interface GetFullActivityOptions {
/**
@ -430,8 +430,8 @@ export interface AttendancePeriod {
}
export interface AttendanceMeta {
dates: Array<string>;
sessions: Array<string>;
dates: string[];
sessions: string[];
start_date: string;
end_date: string;
percentage: string;
@ -480,12 +480,12 @@ export type RewardPurchaseResponse = ClassChartsResponse<
export interface PupilFieldsData {
note: string;
fields: Array<{
fields: {
id: number;
name: string;
graphic: string;
value: string;
}>;
}[];
}
export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>;