1
0
Fork 0
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:
Tim 2022-03-28 14:36:08 +02:00 committed by GitHub
parent 0f21e7d744
commit a0b7326e3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -68,7 +68,7 @@ export class ClasschartsClient {
return data?.user; return data?.user;
} }
/** /**
* Get's the logged in student's general activity * Gets the logged in student's general activity
* @param options GetActivityOptions * @param options GetActivityOptions
* @returns Activity data * @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 * Gets the logged in students behaviour points
* @param options GetBehaviourOptions * @param options GetBehaviourOptions