mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 19:59:37 +00:00
feat: add selectPupil to parent client
This commit is contained in:
parent
346aaccade
commit
fd75c3ff75
2 changed files with 24 additions and 7 deletions
|
|
@ -9,6 +9,8 @@ import { API_BASE_PARENT, BASE_URL } from "./consts";
|
||||||
export class ClasschartsParentClient extends ClasschartsClient {
|
export class ClasschartsParentClient extends ClasschartsClient {
|
||||||
private password = "";
|
private password = "";
|
||||||
private email = "";
|
private email = "";
|
||||||
|
// @ts-expect-error Init in .login
|
||||||
|
public pupils: GetPupilsResponse;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param email Parents email address
|
* @param email Parents email address
|
||||||
|
|
@ -55,13 +57,11 @@ export class ClasschartsParentClient extends ClasschartsClient {
|
||||||
sessionID = JSON.parse(
|
sessionID = JSON.parse(
|
||||||
sessionID.substring(sessionID.indexOf("{"), sessionID.length)
|
sessionID.substring(sessionID.indexOf("{"), sessionID.length)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.sessionId = sessionID.session_id;
|
this.sessionId = sessionID.session_id;
|
||||||
|
this.pupils = await this.getPupils();
|
||||||
const pupil = await this.getPupils();
|
if (!this.pupils) throw new Error("Account has no pupils attached");
|
||||||
|
this.studentId = this.pupils[0].id;
|
||||||
this.studentId = pupil[0].id;
|
this.studentName = this.pupils[0].name;
|
||||||
this.studentName = pupil[0].name;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get Pupil details
|
* Get Pupil details
|
||||||
|
|
@ -72,4 +72,21 @@ export class ClasschartsParentClient extends ClasschartsClient {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pupilId Pupil ID obtained from this.pupils or getPupils
|
||||||
|
*/
|
||||||
|
async selectPupil(pupilId: number): Promise<void> {
|
||||||
|
if (!pupilId) throw new Error("No pupil ID specified");
|
||||||
|
const pupils = this.pupils;
|
||||||
|
for (let i = 0; i < pupils.length; i++) {
|
||||||
|
const pupil = pupils[i];
|
||||||
|
if (pupil.id == pupilId) {
|
||||||
|
this.studentId = pupil.id;
|
||||||
|
this.studentName = pupil.name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("No pupil with specified ID returned");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue