35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { BaseApi, classroomio } from '$lib/utils/services/api';
|
|
|
|
import type { DashStatsSuccess } from '$features/org/utils/types';
|
|
|
|
/**
|
|
* API class for organization dashboard analytics
|
|
*/
|
|
class DashStatApi extends BaseApi {
|
|
stats = $state<DashStatsSuccess['data']>({
|
|
recentCertifications: [],
|
|
numberOfCourses: 0,
|
|
totalCertificates: 0,
|
|
totalStudents: 0,
|
|
topCourses: []
|
|
});
|
|
|
|
/**
|
|
* Fetches dashboard statistics for an organization
|
|
* @param orgId Optional organization ID
|
|
* @param siteName Optional site name
|
|
* @returns Organization analytics data (certifications, courses, students, top courses)
|
|
*/
|
|
async fetchOrgStats({ orgId, siteName }: { orgId?: string; siteName?: string }) {
|
|
await this.execute<typeof classroomio.dash.stats.$get>({
|
|
requestFn: () => classroomio.dash.stats.$get({ query: { orgId, siteName } }),
|
|
logContext: 'fetching organization stats',
|
|
onSuccess: (response) => {
|
|
this.stats = response.data;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export const dashStatApi = new DashStatApi();
|