Skip to content

Commit 118c384

Browse files
authored
feat: add changePassword parent method (#40)
1 parent c42dd71 commit 118c384

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,11 @@ Selects a pupil to make subsequent requests for.
336336
```typescript
337337
await client.selectPupil(123);
338338
```
339+
340+
## `.changePassword`
341+
342+
Changes the parent's password.
343+
344+
```typescript
345+
await client.changePassword("oldPassword", "newPassword");
346+
```

src/core/parentClient.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { GetPupilsResponse } from "../types.ts";
1+
import type { ChangePasswordResponse, GetPupilsResponse } from "../types.ts";
22

33
import { BaseClient } from "../core/baseClient.ts";
44
import { API_BASE_PARENT, BASE_URL } from "../utils/consts.ts";
@@ -88,4 +88,31 @@ export class ParentClient extends BaseClient {
8888
}
8989
throw new Error("No pupil with specified ID returned");
9090
}
91+
/**
92+
* Changes the login password for the current parent account
93+
* @param currentPassword Current password
94+
* @param newPassword New password
95+
* @returns Whether the request was successful
96+
*/
97+
async changePassword(
98+
currentPassword: string,
99+
newPassword: string,
100+
): Promise<ChangePasswordResponse> {
101+
const formData = new URLSearchParams();
102+
formData.append("current", currentPassword);
103+
formData.append("new", newPassword);
104+
formData.append("repeat", newPassword);
105+
return (
106+
await this.makeAuthedRequest(
107+
this.API_BASE + "/password",
108+
{
109+
method: "POST",
110+
body: formData,
111+
headers: {
112+
"Content-Type": "application/x-www-form-urlencoded",
113+
},
114+
},
115+
)
116+
);
117+
}
91118
}

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ export interface PupilFieldsData {
490490

491491
export type PupilFieldsResponse = ClassChartsResponse<PupilFieldsData, []>;
492492

493+
export type ChangePasswordResponse = ClassChartsResponse<[], []>;
494+
493495
export interface GetStudentCodeOptions {
494496
/**
495497
* Date of birth, in format YYYY-MM-DD

0 commit comments

Comments
 (0)