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

add getcode endpoint

This commit is contained in:
James Cook 2023-05-04 11:54:14 +01:00
parent 4cfb4128de
commit fad2b99ff8
3 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"classcharts-api": minor
---
Added getcode endpoint

View file

@ -10,6 +10,8 @@ import type {
GetActivityOptions,
GetAttendanceOptions,
GetBehaviourOptions,
GetCodeOptions,
GetCodeResponse,
GetFullActivityOptions,
GetHomeworkOptions,
GetLessonsOptions,
@ -319,4 +321,19 @@ export class BaseClient {
)
).data;
}
/**
* Gets the current student's code
* @param options GetCodeOptions
* @param options.dateOfBirth Date of birth in the format YYYY-MM-DD
* @returns
*/
async getCode(options: GetCodeOptions): Promise<GetCodeResponse> {
const data = await this.makeAuthedRequest(this.API_BASE + "/getcode", {
method: "POST",
body: JSON.stringify({
date: options.dateOfBirth,
}),
});
return data;
}
}

View file

@ -429,3 +429,20 @@ export interface AttendanceDate {
}
// TODO: Update typings to include meta response. Currently not possible since I don't have access
export type AttendanceResponse = Record<string, AttendanceDate>[];
export interface GetCodeOptions {
/**
* Date of birth, in format YYYY-MM-DD
*/
dateOfBirth: string;
}
export interface GetCodeResponseData {
code: string;
}
export type GetCodeResponseMeta = [];
export type GetCodeResponse = ClassChartsResponse<
GetCodeResponseData,
GetCodeResponseMeta
>;