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:
parent
c42dd71cdf
commit
118c384131
3 changed files with 38 additions and 1 deletions
|
|
@ -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");
|
||||
```
|
||||
|
|
@ -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",
|
||||
},
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue