Skip to content

Commit 40c370c

Browse files
feat: add getcode endpoint (#26)
1 parent c8f7ab4 commit 40c370c

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/core/studentClient.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { API_BASE_STUDENT, BASE_URL } from "../utils/consts.ts";
22
import { BaseClient } from "../core/baseClient.ts";
33
import { parseCookies } from "../utils/utils.ts";
4-
import { RewardPurchaseResponse, RewardsResponse } from "../types.ts";
4+
import {
5+
GetStudentCodeOptions,
6+
GetStudentCodeResponse,
7+
RewardPurchaseResponse,
8+
RewardsResponse,
9+
} from "../types.ts";
510

611
/**
712
* Student Client
@@ -91,4 +96,22 @@ export class StudentClient extends BaseClient {
9196
)
9297
);
9398
}
99+
100+
/**
101+
* Gets the current student's student code
102+
* @param options GetStudentCodeOptions
103+
* @param options.dateOfBirth Date of birth in the format YYYY-MM-DD
104+
* @returns
105+
*/
106+
async getStudentCode(
107+
options: GetStudentCodeOptions,
108+
): Promise<GetStudentCodeResponse> {
109+
const data = await this.makeAuthedRequest(this.API_BASE + "/getcode", {
110+
method: "POST",
111+
body: JSON.stringify({
112+
date: options.dateOfBirth,
113+
}),
114+
});
115+
return data;
116+
}
94117
}

src/types.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,20 @@ export interface PupilFieldsData {
489489
}
490490

491491
export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>;
492+
493+
export interface GetStudentCodeOptions {
494+
/**
495+
* Date of birth, in format YYYY-MM-DD
496+
*/
497+
dateOfBirth: string;
498+
}
499+
500+
export interface GetStudentCodeResponseData {
501+
code: string;
502+
}
503+
504+
export type GetStudentCodeResponseMeta = [];
505+
export type GetStudentCodeResponse = ClassChartsResponse<
506+
GetStudentCodeResponseData,
507+
GetStudentCodeResponseMeta
508+
>;

0 commit comments

Comments
 (0)