124 lines
2.9 KiB
TypeScript
124 lines
2.9 KiB
TypeScript
import axios from 'axios';
|
|
|
|
const api = axios.create({
|
|
baseURL: '/api',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
export interface SiteConfig {
|
|
siteTitle: string;
|
|
subtitle: string;
|
|
channels: { name: string; url: string }[];
|
|
shortText: string;
|
|
quizParticipationPoints: number;
|
|
quizCorrectAnswerPoints: number;
|
|
}
|
|
|
|
export interface RegisterResponse {
|
|
userId: number;
|
|
trackingCode: string;
|
|
}
|
|
|
|
export interface LoginResponse {
|
|
userId: number;
|
|
fullName: string;
|
|
contact: string;
|
|
isQuizCompleted: boolean;
|
|
khatmSelections: number[];
|
|
}
|
|
|
|
export interface Question {
|
|
id: number;
|
|
questionText: string;
|
|
options: string[];
|
|
}
|
|
|
|
export interface QuizSubmitResponse {
|
|
participationPoints: number;
|
|
correctCount: number;
|
|
totalQuizPoints: number;
|
|
totalScore: number;
|
|
}
|
|
|
|
export interface UserQuizResponse {
|
|
questions: UserQuestion[];
|
|
participationPoints: number;
|
|
correctCount: number;
|
|
totalQuizPoints: number;
|
|
}
|
|
|
|
export interface UserQuestion {
|
|
id: number;
|
|
questionText: string;
|
|
options: string[];
|
|
selectedOption: number;
|
|
isCorrect: boolean;
|
|
}
|
|
|
|
export interface KhatmItem {
|
|
id: number;
|
|
title: string;
|
|
url?: string;
|
|
points: number;
|
|
}
|
|
|
|
export interface KhatmSaveResponse {
|
|
success: boolean;
|
|
totalScore: number;
|
|
}
|
|
|
|
export interface UserScore {
|
|
totalScore: number;
|
|
}
|
|
|
|
export interface AdminReportItem {
|
|
userId: number;
|
|
fullName: string;
|
|
contact: string;
|
|
trackingCode: string;
|
|
hasTakenQuiz: boolean;
|
|
participationPoints: number;
|
|
correctCount: number;
|
|
totalQuizPoints: number;
|
|
khatmTitles: string;
|
|
totalScore: number;
|
|
}
|
|
|
|
// Config
|
|
export const getConfig = () => api.get<SiteConfig>('/config').then(r => r.data);
|
|
|
|
// User
|
|
export const registerUser = (fullName: string, contact: string) =>
|
|
api.post<RegisterResponse>('/user/register', { fullName, contact }).then(r => r.data);
|
|
|
|
export const loginUser = (trackingCode: string) =>
|
|
api.post<LoginResponse>('/user/login', { trackingCode }).then(r => r.data);
|
|
|
|
export const getUserScore = (userId: number) =>
|
|
api.get<UserScore>(`/user/${userId}/score`).then(r => r.data);
|
|
|
|
// Quiz
|
|
export const getQuestions = () =>
|
|
api.get<Question[]>('/quiz/questions').then(r => r.data);
|
|
|
|
export const submitQuiz = (userId: number, answers: { questionId: number; selectedOption: number }[]) =>
|
|
api.post<QuizSubmitResponse>('/quiz/submit', { userId, answers }).then(r => r.data);
|
|
|
|
export const getUserQuiz = (userId: number) =>
|
|
api.get<UserQuizResponse>(`/quiz/user/${userId}`).then(r => r.data);
|
|
|
|
// Khatm
|
|
export const getKhatmItems = () =>
|
|
api.get<KhatmItem[]>('/khatm/items').then(r => r.data);
|
|
|
|
export const saveKhatmSelections = (userId: number, selections: { khatmItemId: number; isSelected: boolean }[]) =>
|
|
api.post<KhatmSaveResponse>('/khatm/save', { userId, selections }).then(r => r.data);
|
|
|
|
// Admin
|
|
export const getAdminReport = (password: string) =>
|
|
api.get<AdminReportItem[]>('/admin/report', { params: { password } }).then(r => r.data);
|
|
|
|
export default api;
|