UNPKG

mcp-quiz-server

Version:

🧠 AI-Powered Quiz Management via Model Context Protocol (MCP) - Create, manage, and take quizzes directly from VS Code, Claude, and other AI agents.

135 lines • 4.62 kB
import { ApiClient } from './ApiClient'; import { AuthService } from './AuthService'; export class DashboardService { constructor() { this.apiClient = ApiClient.getInstance(); this.authService = AuthService.getInstance(); } async getDashboardData() { try { const [userInfo, stats, recentQuizzes, recentActivity] = await Promise.all([ this.getUserInfo(), this.getDashboardStats(), this.getRecentQuizzes(), this.getRecentActivity(), ]); return { user: userInfo, stats, recentQuizzes, recentActivity, lastUpdated: new Date().toISOString(), }; } catch (error) { console.error('Failed to load dashboard data:', error); throw new Error('Unable to load dashboard. Please try again.'); } } async getUserInfo() { try { const response = await this.apiClient.get('/dashboard/api/user'); return response.data; } catch (error) { console.error('Failed to load user info:', error); throw new Error('Unable to load user information'); } } async getDashboardStats() { try { const response = await this.apiClient.get('/dashboard/api/stats'); return response.data; } catch (error) { console.error('Failed to load dashboard stats:', error); return { totalQuizzes: 0, totalResponses: 0, recentActivity: 0, completionRate: 0, }; } } async getRecentQuizzes(limit = 5) { try { const response = await this.apiClient.get(`/dashboard/api/quizzes?limit=${limit}&sort=recent`); return response.data.quizzes || []; } catch (error) { console.error('Failed to load recent quizzes:', error); return []; } } async getRecentActivity(limit = 10) { try { const response = await this.apiClient.get(`/dashboard/api/activity?limit=${limit}`); return response.data.activities || []; } catch (error) { console.error('Failed to load recent activity:', error); return []; } } async getQuizAnalytics(timeRange = '30d') { try { const response = await this.apiClient.get(`/dashboard/api/analytics?timeRange=${timeRange}`); return response.data; } catch (error) { console.error('Failed to load quiz analytics:', error); throw new Error('Unable to load analytics data'); } } async updateProfile(profileData) { try { const response = await this.apiClient.put('/dashboard/api/user/profile', profileData); return response.data; } catch (error) { console.error('Failed to update profile:', error); throw new Error('Unable to update profile. Please try again.'); } } async createQuiz(quizData) { try { const response = await this.apiClient.post('/quiz', quizData); return response.data; } catch (error) { console.error('Failed to create quiz:', error); throw new Error('Unable to create quiz. Please try again.'); } } async deleteQuiz(quizId) { try { await this.apiClient.delete(`/quiz/${quizId}`); } catch (error) { console.error('Failed to delete quiz:', error); throw new Error('Unable to delete quiz. Please try again.'); } } async getQuiz(quizId) { try { const response = await this.apiClient.get(`/quiz/${quizId}`); return response.data; } catch (error) { console.error('Failed to load quiz:', error); throw new Error('Unable to load quiz details'); } } async searchQuizzes(params) { try { const queryString = new URLSearchParams(params).toString(); const response = await this.apiClient.get(`/dashboard/api/quizzes/search?${queryString}`); return response.data; } catch (error) { console.error('Failed to search quizzes:', error); throw new Error('Search failed. Please try again.'); } } } //# sourceMappingURL=DashboardService.js.map