mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 11:58:13 +00:00
feat: getFullActivity
Co-Authored-By: Tim <65774333+timthedev07@users.noreply.github.com>
This commit is contained in:
parent
0f21e7d744
commit
eea157566c
2 changed files with 43 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ import type {
|
|||
DetentionsResponse,
|
||||
GetActivityOptions,
|
||||
GetBehaviourOptions,
|
||||
GetFullActivityOptions,
|
||||
GetHomeworkOptions,
|
||||
GetLessonsOptions,
|
||||
Homework,
|
||||
|
|
@ -68,7 +69,7 @@ export class ClasschartsClient {
|
|||
return data?.user;
|
||||
}
|
||||
/**
|
||||
* Get's the logged in student's general activity
|
||||
* This function is only used for pagination, you likely want client.getFullActivity
|
||||
* @param options GetActivityOptions
|
||||
* @returns Activity data
|
||||
*/
|
||||
|
|
@ -84,7 +85,35 @@ export class ClasschartsClient {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for getActivity, returns all the data from the selected dates
|
||||
* @param options GetFullActivityOptions
|
||||
* @returns Activity Data
|
||||
*/
|
||||
async getFullActivity(
|
||||
options: GetFullActivityOptions
|
||||
): Promise<ActivityResponse> {
|
||||
let data: ActivityResponse = [];
|
||||
let prevLast: number | undefined;
|
||||
let gotData = true;
|
||||
while (gotData) {
|
||||
const params: GetActivityOptions = {
|
||||
from: options.from,
|
||||
to: options.to,
|
||||
};
|
||||
if (prevLast) {
|
||||
params.last_id = String(prevLast);
|
||||
}
|
||||
const fragment = await this.getActivity(params);
|
||||
if (!fragment || !fragment.length) {
|
||||
gotData = false;
|
||||
} else {
|
||||
data = data.concat(fragment);
|
||||
prevLast = fragment[fragment.length - 1].id;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/**
|
||||
* Gets the logged in students behaviour points
|
||||
* @param options GetBehaviourOptions
|
||||
|
|
|
|||
11
src/types.ts
11
src/types.ts
|
|
@ -300,3 +300,14 @@ export interface Pupil extends Student {
|
|||
messages_count: number;
|
||||
}
|
||||
export type GetPupilsResponse = Array<Pupil>;
|
||||
|
||||
export interface GetFullActivityOptions {
|
||||
/**
|
||||
* From date, in format YYYY-MM-DD
|
||||
*/
|
||||
from: string;
|
||||
/**
|
||||
* To date, in format YYYY-MM-DD
|
||||
*/
|
||||
to: string;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue