From b37e3dc94b4c3655733fc470d3b1d84be186f5ed Mon Sep 17 00:00:00 2001 From: Isaac Hatton Date: Sun, 8 Oct 2023 11:25:29 +0000 Subject: [PATCH] feat: add changePassword (parent app) endpoint --- src/core/parentClient.ts | 27 ++++++++++++++++++++++++++- src/types.ts | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/core/parentClient.ts b/src/core/parentClient.ts index add0d6b..65d241c 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,29 @@ export class ParentClient extends BaseClient { } throw new Error("No pupil with specified ID returned"); } + /** + * Changes the login password for this parent's account + * @param current Current password + * @param new New password + * @returns whether it was successful or not + */ + async changePassword(this: ParentClient, current: string, newPassword: string): Promise{ + const formData = new URLSearchParams(); + formData.append("current", current); + formData.append("new", newPassword); + formData.append("repeat", newPassword); + const headers = new Headers({ + "Content-Type": "application/x-www-form-urlencoded", + }); + return ( + await this.makeAuthedRequest( + this.API_BASE + "/password", + { + method: "POST", + body: formData, + headers: headers, + }, + ) + ); + } } 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