mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 19:59:37 +00:00
fix: cleanup code
This commit is contained in:
parent
33f235c7d7
commit
d9a234bd7e
6 changed files with 2 additions and 72 deletions
|
|
@ -18,8 +18,7 @@
|
|||
"undici": "^4.11.3"
|
||||
},
|
||||
"files": [
|
||||
"dist/**",
|
||||
"types.d.ts"
|
||||
"dist/**"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.12",
|
||||
|
|
|
|||
55
src/api.ts
55
src/api.ts
|
|
@ -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<Student> {
|
||||
const client = new ClasschartsClient(studentCode, dateOfBirth)
|
||||
return await client.getStudentInfo()
|
||||
}
|
||||
export async function getActivity(
|
||||
studentCode: string,
|
||||
dateOfBirth?: string,
|
||||
options?: GetActivityOptions
|
||||
): Promise<ActivityResponse> {
|
||||
const client = new ClasschartsClient(studentCode, dateOfBirth)
|
||||
return await client.getActivity(options)
|
||||
}
|
||||
export async function getBehaviour(
|
||||
studentCode: string,
|
||||
dateOfBirth?: string,
|
||||
options?: GetBehaviourOptions
|
||||
): Promise<BehaviourResponse> {
|
||||
const client = new ClasschartsClient(studentCode, dateOfBirth)
|
||||
return await client.getBehaviour(options)
|
||||
}
|
||||
export async function listHomeworks(
|
||||
studentCode: string,
|
||||
dateOfBirth?: string,
|
||||
options?: GetHomeworkOptions
|
||||
): Promise<HomeworksResponse> {
|
||||
const client = new ClasschartsClient(studentCode, dateOfBirth)
|
||||
return await client.listHomeworks(options)
|
||||
}
|
||||
export async function getLessons(
|
||||
studentCode: string,
|
||||
dateOfBirth?: string,
|
||||
options?: GetLessonsOptions
|
||||
): Promise<LessonsResponse> {
|
||||
const client = new ClasschartsClient(studentCode, dateOfBirth)
|
||||
return await client.getLessons(options)
|
||||
}
|
||||
|
|
@ -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<Student> {
|
||||
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<HomeworksResponse> {
|
||||
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<LessonsResponse> {
|
||||
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))
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
export * from './client'
|
||||
export * from './api'
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue