mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 11:58:13 +00:00
Update baseClient.ts
New method
This commit is contained in:
parent
0f21e7d744
commit
a0b7326e3c
1 changed files with 30 additions and 1 deletions
|
|
@ -68,7 +68,7 @@ export class ClasschartsClient {
|
|||
return data?.user;
|
||||
}
|
||||
/**
|
||||
* Get's the logged in student's general activity
|
||||
* Gets the logged in student's general activity
|
||||
* @param options GetActivityOptions
|
||||
* @returns Activity data
|
||||
*/
|
||||
|
|
@ -85,6 +85,35 @@ export class ClasschartsClient {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the activities from and to the indicated dates.
|
||||
* An abstraction on top of the getActivity method, it fetches everything in the given interval instead of returning a fragment.
|
||||
*/
|
||||
async getFullActivity(from: string, to: string, client: ClasschartsClient) {
|
||||
let data: ActivityResponse = [];
|
||||
let prevLast: number | undefined;
|
||||
|
||||
while (true) {
|
||||
const params: GetActivityOptions = {
|
||||
from,
|
||||
to,
|
||||
};
|
||||
if (prevLast) {
|
||||
params.last_id = `${prevLast}`;
|
||||
}
|
||||
const fragment = await client.getActivity(params);
|
||||
|
||||
if (!fragment || !fragment.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
data = data.concat(fragment);
|
||||
prevLast = fragment[fragment.length - 1].id;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the logged in students behaviour points
|
||||
* @param options GetBehaviourOptions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue