From d9a234bd7e9b6a73279265272aaf1d81f84c077b Mon Sep 17 00:00:00 2001 From: James Cook Date: Sun, 12 Dec 2021 14:33:32 +0000 Subject: [PATCH] fix: cleanup code --- package.json | 3 +-- src/api.ts | 55 -------------------------------------- src/client.ts | 5 +--- src/index.ts | 1 - src/tests/test.ts | 10 ------- types.d.ts => src/types.ts | 0 6 files changed, 2 insertions(+), 72 deletions(-) delete mode 100644 src/api.ts delete mode 100644 src/tests/test.ts rename types.d.ts => src/types.ts (100%) diff --git a/package.json b/package.json index 2183ac5..77178f6 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,7 @@ "undici": "^4.11.3" }, "files": [ - "dist/**", - "types.d.ts" + "dist/**" ], "devDependencies": { "@types/node": "^16.11.12", diff --git a/src/api.ts b/src/api.ts deleted file mode 100644 index 2305564..0000000 --- a/src/api.ts +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Helper functions for requesting individual students instead of making a whole client - * Using a client should be prefered over performance reasons - */ -import { ClasschartsClient } from '.' -import { - ActivityResponse, - BehaviourResponse, - GetActivityOptions, - GetBehaviourOptions, - GetHomeworkOptions, - GetLessonsOptions, - HomeworksResponse, - LessonsResponse, - Student, -} from '../types' -export async function getStudentInfo( - studentCode: string, - dateOfBirth?: string -): Promise { - const client = new ClasschartsClient(studentCode, dateOfBirth) - return await client.getStudentInfo() -} -export async function getActivity( - studentCode: string, - dateOfBirth?: string, - options?: GetActivityOptions -): Promise { - const client = new ClasschartsClient(studentCode, dateOfBirth) - return await client.getActivity(options) -} -export async function getBehaviour( - studentCode: string, - dateOfBirth?: string, - options?: GetBehaviourOptions -): Promise { - const client = new ClasschartsClient(studentCode, dateOfBirth) - return await client.getBehaviour(options) -} -export async function listHomeworks( - studentCode: string, - dateOfBirth?: string, - options?: GetHomeworkOptions -): Promise { - const client = new ClasschartsClient(studentCode, dateOfBirth) - return await client.listHomeworks(options) -} -export async function getLessons( - studentCode: string, - dateOfBirth?: string, - options?: GetLessonsOptions -): Promise { - const client = new ClasschartsClient(studentCode, dateOfBirth) - return await client.getLessons(options) -} diff --git a/src/client.ts b/src/client.ts index d9d161c..8aac63c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -11,7 +11,7 @@ import { HomeworksResponse, LessonsResponse, Student, -} from '../types' +} from './types' import { API_BASE, BASE_URL } from './consts' /** * The base client @@ -97,7 +97,6 @@ export class ClasschartsClient { * @returns Student object */ async getStudentInfo(): Promise { - if (!this.authCookies) throw new Error('Not authenticated') const data = await this.makeAuthedRequest(API_BASE + '/ping', { method: 'POST', body: 'include_date=true', @@ -149,7 +148,6 @@ export class ClasschartsClient { async listHomeworks( options?: GetHomeworkOptions ): Promise { - if (!this.authCookies) throw new Error('Not authenticated') const params = new URLSearchParams() if (options?.displayDate) params.append('display_date', String(options?.displayDate)) options?.fromDate && params.append('from', String(options?.fromDate)) @@ -177,7 +175,6 @@ export class ClasschartsClient { * @returns Array of lessons */ async getLessons(options?: GetLessonsOptions): Promise { - if (!this.authCookies) throw new Error('Not authenticated') if (!options?.date) throw new Error('No date specified') const params = new URLSearchParams() params.append('date', String(options?.date)) diff --git a/src/index.ts b/src/index.ts index 5992cba..83dae76 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1 @@ export * from './client' -export * from './api' diff --git a/src/tests/test.ts b/src/tests/test.ts deleted file mode 100644 index d09ed70..0000000 --- a/src/tests/test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ClasschartsClient } from '../client' -const { code, dob } = require('../../src/tests/config.json') -async function main() { - const client = new ClasschartsClient(code, dob) - await client.init() - console.log(await client.getBehaviour()) - console.log(await client.getActivity()) -} - -main() diff --git a/types.d.ts b/src/types.ts similarity index 100% rename from types.d.ts rename to src/types.ts