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,
|
DetentionsResponse,
|
||||||
GetActivityOptions,
|
GetActivityOptions,
|
||||||
GetBehaviourOptions,
|
GetBehaviourOptions,
|
||||||
|
GetFullActivityOptions,
|
||||||
GetHomeworkOptions,
|
GetHomeworkOptions,
|
||||||
GetLessonsOptions,
|
GetLessonsOptions,
|
||||||
Homework,
|
Homework,
|
||||||
|
|
@ -68,7 +69,7 @@ export class ClasschartsClient {
|
||||||
return data?.user;
|
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
|
* @param options GetActivityOptions
|
||||||
* @returns Activity data
|
* @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
|
* Gets the logged in students behaviour points
|
||||||
* @param options GetBehaviourOptions
|
* @param options GetBehaviourOptions
|
||||||
|
|
|
||||||
13
src/types.ts
13
src/types.ts
|
|
@ -299,4 +299,15 @@ export interface Pupil extends Student {
|
||||||
announcements_count: number;
|
announcements_count: number;
|
||||||
messages_count: number;
|
messages_count: number;
|
||||||
}
|
}
|
||||||
export type GetPupilsResponse = Array<Pupil>;
|
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