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

feat: add changePassword (parent app) endpoint

This commit is contained in:
Isaac Hatton 2023-10-08 11:25:29 +00:00
parent c42dd71cdf
commit b37e3dc94b
2 changed files with 28 additions and 1 deletions

View file

@ -1,4 +1,4 @@
import type { GetPupilsResponse } from "../types.ts"; import type { ChangePasswordResponse, GetPupilsResponse } from "../types.ts";
import { BaseClient } from "../core/baseClient.ts"; import { BaseClient } from "../core/baseClient.ts";
import { API_BASE_PARENT, BASE_URL } from "../utils/consts.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"); 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<ChangePasswordResponse>{
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,
},
)
);
}
} }

View file

@ -490,6 +490,8 @@ export interface PupilFieldsData {
export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>; export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>;
export type ChangePasswordResponse = ClassChartsResponse<[], []>;
export interface GetStudentCodeOptions { export interface GetStudentCodeOptions {
/** /**
* Date of birth, in format YYYY-MM-DD * Date of birth, in format YYYY-MM-DD