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

feat: add getcode endpoint (#26)

This commit is contained in:
James Cook 2023-09-24 21:17:15 +01:00 committed by GitHub
parent c8f7ab4fb0
commit 40c370c151
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View file

@ -1,7 +1,12 @@
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts";
import { BaseClient } from "../core/baseClient.ts";
import { parseCookies } from "../utils/utils.ts";
import { RewardPurchaseResponse, RewardsResponse } from "../types.ts";
import {
GetStudentCodeOptions,
GetStudentCodeResponse,
RewardPurchaseResponse,
RewardsResponse,
} from "../types.ts";
/**
* 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 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
>;