diff --git a/README.md b/README.md index ffa118a..2440fa4 100644 --- a/README.md +++ b/README.md @@ -336,3 +336,11 @@ Selects a pupil to make subsequent requests for. ```typescript await client.selectPupil(123); ``` + +## `.changePassword` + +Changes the parent's password. + +```typescript +await client.changePassword("oldPassword", "newPassword"); +``` \ No newline at end of file diff --git a/src/core/parentClient.ts b/src/core/parentClient.ts index add0d6b..5f1f0ea 100644 --- a/src/core/parentClient.ts +++ b/src/core/parentClient.ts @@ -1,4 +1,4 @@ -import type { GetPupilsResponse } from "../types.ts"; +import type { ChangePasswordResponse, GetPupilsResponse } from "../types.ts"; import { BaseClient } from "../core/baseClient.ts"; import { API_BASE_PARENT, BASE_URL } from "../utils/consts.ts"; @@ -88,4 +88,31 @@ export class ParentClient extends BaseClient { } throw new Error("No pupil with specified ID returned"); } + /** + * Changes the login password for the current parent account + * @param currentPassword Current password + * @param newPassword New password + * @returns Whether the request was successful + */ + async changePassword( + currentPassword: string, + newPassword: string, + ): Promise { + const formData = new URLSearchParams(); + formData.append("current", currentPassword); + formData.append("new", newPassword); + formData.append("repeat", newPassword); + return ( + await this.makeAuthedRequest( + this.API_BASE + "/password", + { + method: "POST", + body: formData, + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + }, + ) + ); + } } diff --git a/src/types.ts b/src/types.ts index 7bdf02d..2a27865 100644 --- a/src/types.ts +++ b/src/types.ts @@ -490,6 +490,8 @@ export interface PupilFieldsData { export type PupilFieldsResponse = ClassChartsResponse; +export type ChangePasswordResponse = ClassChartsResponse<[], []>; + export interface GetStudentCodeOptions { /** * Date of birth, in format YYYY-MM-DD