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

style: prettier and eslint

This commit is contained in:
James Cook 2022-03-12 11:37:28 +00:00
parent e1ac2b1364
commit efba7086ea
8 changed files with 33 additions and 2803 deletions

View file

@ -1,26 +1,24 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/javascript-node // https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/javascript-node
{ {
"name": "Node.js", "name": "Node.js",
"build": { "build": {
"dockerfile": "Dockerfile", "dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 16, 14, 12. // Update 'VARIANT' to pick a Node version: 16, 14, 12.
// Append -bullseye or -buster to pin to an OS version. // Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon. // Use -bullseye variants on local arm64/Apple Silicon.
"args": { "args": {
"VARIANT": "16-bullseye" "VARIANT": "16-bullseye"
} }
}, },
// Set *default* container specific settings.json values on container create. // Set *default* container specific settings.json values on container create.
"settings": {}, "settings": {},
// Add the IDs of extensions you want installed when the container is created. // Add the IDs of extensions you want installed when the container is created.
"extensions": [ "extensions": ["dbaeumer.vscode-eslint"],
"dbaeumer.vscode-eslint" // Use 'forwardPorts' to make a list of ports inside the container available locally.
], // "forwardPorts": [],
// Use 'forwardPorts' to make a list of ports inside the container available locally. // Use 'postCreateCommand' to run commands after the container is created.
// "forwardPorts": [], "postCreateCommand": "pnpm install",
// Use 'postCreateCommand' to run commands after the container is created. // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"postCreateCommand": "pnpm install", "remoteUser": "node"
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. }
"remoteUser": "node"
}

View file

@ -3,3 +3,6 @@ docs
node_modules node_modules
pnpm-lock.yaml pnpm-lock.yaml
package.json package.json
.prettierrc.json
.eslint.js
tsconfig.json

2732
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -30,13 +30,12 @@ export class ClasschartsClient {
* @param API_BASE Base API URL, this is different depending if its called as a parent or student * @param API_BASE Base API URL, this is different depending if its called as a parent or student
*/ */
constructor(API_BASE: string) { constructor(API_BASE: string) {
this.API_BASE = API_BASE this.API_BASE = API_BASE;
} }
public async makeAuthedRequest( public async makeAuthedRequest(
path: string, path: string,
options: Omit<RequestOptions, "origin" | "path"> options: Omit<RequestOptions, "origin" | "path">
) { ) {
if (!this.authCookies) throw new Error("Not authenticated"); if (!this.authCookies) throw new Error("Not authenticated");
const requestOptions: Omit<RequestOptions, "origin" | "path"> = { const requestOptions: Omit<RequestOptions, "origin" | "path"> = {
...options, ...options,
@ -46,7 +45,6 @@ export class ClasschartsClient {
}, },
}; };
const request = await Undici.request(path, requestOptions); const request = await Undici.request(path, requestOptions);
let responseJSON; let responseJSON;
@ -56,14 +54,12 @@ export class ClasschartsClient {
throw new Error("Invalid JSON response recieved"); throw new Error("Invalid JSON response recieved");
} }
if (responseJSON.success == 0) { if (responseJSON.success == 0) {
throw new Error(responseJSON.error); throw new Error(responseJSON.error);
} }
return responseJSON.data; return responseJSON.data;
} }
/** /**
* Gets general information about the logged in student * Gets general information about the logged in student
* @returns Student object * @returns Student object
@ -94,8 +90,6 @@ export class ClasschartsClient {
); );
} }
/** /**
* Gets the logged in students behaviour points * Gets the logged in students behaviour points
* @param options GetBehaviourOptions * @param options GetBehaviourOptions
@ -143,7 +137,7 @@ export class ClasschartsClient {
data[i].description = data[i].description.replace(/&nbsp;/g, ""); data[i].description = data[i].description.replace(/&nbsp;/g, "");
data[i].description = data[i].description.trim(); data[i].description = data[i].description.trim();
} }
console.log(data) console.log(data);
return data; return data;
} }
/** /**

View file

@ -1,2 +1,3 @@
export * from "./parent"; export * from "./parent";
export * from "./student"; export * from "./student";
export * from "./types";

View file

@ -1,21 +1,5 @@
import Undici from "undici"; import Undici from "undici";
import { RequestOptions } from "undici/types/dispatcher"; import type { GetPupilsResponse } from "./types";
import {
ActivityResponse,
AnnouncementsResponse,
BadgesResponse,
BehaviourResponse,
DetentionsResponse,
GetActivityOptions,
GetBehaviourOptions,
GetHomeworkOptions,
GetLessonsOptions,
GetPupilsResponse,
Homework,
HomeworksResponse,
LessonsResponse,
Student,
} from "./types";
import { ClasschartsClient } from "./client"; import { ClasschartsClient } from "./client";
import { API_BASE_PARENT, BASE_URL } from "./consts"; import { API_BASE_PARENT, BASE_URL } from "./consts";
@ -74,7 +58,7 @@ export class ClasschartsParentClient extends ClasschartsClient {
this.sessionId = sessionID.session_id; this.sessionId = sessionID.session_id;
let pupil = await this.getPupils(); const pupil = await this.getPupils();
this.studentId = pupil[0].id; this.studentId = pupil[0].id;
this.studentName = pupil[0].name; this.studentName = pupil[0].name;
@ -84,10 +68,8 @@ export class ClasschartsParentClient extends ClasschartsClient {
* @returns an array fo Pupils connected to this parent's account * @returns an array fo Pupils connected to this parent's account
*/ */
async getPupils(): Promise<GetPupilsResponse> { async getPupils(): Promise<GetPupilsResponse> {
let pupils = this.makeAuthedRequest(this.API_BASE + "/pupils", { return this.makeAuthedRequest(this.API_BASE + "/pupils", {
method: "GET", method: "GET",
}); });
return pupils;
} }
} }

View file

@ -1,22 +1,6 @@
import Undici from "undici"; import Undici from "undici";
import { RequestOptions } from "undici/types/dispatcher";
import {
ActivityResponse,
AnnouncementsResponse,
BadgesResponse,
BehaviourResponse,
DetentionsResponse,
GetActivityOptions,
GetBehaviourOptions,
GetHomeworkOptions,
GetLessonsOptions,
Homework,
HomeworksResponse,
LessonsResponse,
Student,
} from "./types";
import { API_BASE_STUDENT, BASE_URL } from "./consts"; import { API_BASE_STUDENT, BASE_URL } from "./consts";
import {ClasschartsClient} from "./client" import { ClasschartsClient } from "./client";
/** /**
* The base client * The base client
*/ */
@ -31,7 +15,7 @@ export class ClasschartsStudentClient extends ClasschartsClient {
* @param dateOfBirth Student's date of birth * @param dateOfBirth Student's date of birth
*/ */
constructor(studentCode: string, dateOfBirth?: string) { constructor(studentCode: string, dateOfBirth?: string) {
super(API_BASE_STUDENT) super(API_BASE_STUDENT);
this.studentCode = String(studentCode); this.studentCode = String(studentCode);
this.dateOfBirth = String(dateOfBirth); this.dateOfBirth = String(dateOfBirth);
} }

View file

@ -299,4 +299,4 @@ export interface Pupil extends Student {
announcements_count: number; announcements_count: number;
messages_count: number; messages_count: number;
} }
export type GetPupilsResponse = Array<Pupil>; export type GetPupilsResponse = Array<Pupil>;