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 changePassword parent method (#40)

This commit is contained in:
Isaac Hatton 2023-10-08 21:02:01 +01:00 committed by GitHub
parent c42dd71cdf
commit 118c384131
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

View file

@ -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");
```

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 { 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<ChangePasswordResponse> {
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",
},
},
)
);
}
}

View file

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