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

fix: move method to parent client

This commit is contained in:
James Cook 2023-09-24 21:16:20 +01:00
parent 53a0ed8310
commit 13f409a009
3 changed files with 41 additions and 18 deletions

View file

@ -9,8 +9,6 @@ import type {
GetActivityOptions, GetActivityOptions,
GetAttendanceOptions, GetAttendanceOptions,
GetBehaviourOptions, GetBehaviourOptions,
GetCodeOptions,
GetCodeResponse,
GetFullActivityOptions, GetFullActivityOptions,
GetHomeworkOptions, GetHomeworkOptions,
GetLessonsOptions, GetLessonsOptions,
@ -309,19 +307,4 @@ export class BaseClient {
}, },
); );
} }
/**
* 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

@ -1,7 +1,12 @@
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts"; import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts";
import { BaseClient } from "../core/baseClient.ts"; import { BaseClient } from "../core/baseClient.ts";
import { parseCookies } from "../utils/utils.ts"; import { parseCookies } from "../utils/utils.ts";
import { RewardPurchaseResponse, RewardsResponse } from "../types.ts"; import {
GetStudentCodeOptions,
GetStudentCodeResponse,
RewardPurchaseResponse,
RewardsResponse,
} from "../types.ts";
/** /**
* Student Client * Student Client
@ -91,4 +96,22 @@ export class StudentClient extends BaseClient {
) )
); );
} }
/**
* Gets the current student's student code
* @param options GetStudentCodeOptions
* @param options.dateOfBirth Date of birth in the format YYYY-MM-DD
* @returns
*/
async getStudentCode(
options: GetStudentCodeOptions,
): Promise<GetStudentCodeResponse> {
const data = await this.makeAuthedRequest(this.API_BASE + "/getcode", {
method: "POST",
body: JSON.stringify({
date: options.dateOfBirth,
}),
});
return data;
}
} }

View file

@ -489,3 +489,20 @@ export interface PupilFieldsData {
} }
export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>; export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>;
export interface GetStudentCodeOptions {
/**
* Date of birth, in format YYYY-MM-DD
*/
dateOfBirth: string;
}
export interface GetStudentCodeResponseData {
code: string;
}
export type GetStudentCodeResponseMeta = [];
export type GetStudentCodeResponse = ClassChartsResponse<
GetStudentCodeResponseData,
GetStudentCodeResponseMeta
>;