Spaces:
Running
Running
File size: 4,680 Bytes
29bcc71 15a6597 29bcc71 40181ed 4d60cbf 1878f24 40181ed 29bcc71 4d60cbf 29bcc71 0d45cfb 29bcc71 68c74e3 87361b9 29bcc71 68c74e3 29bcc71 5d5d3e8 29bcc71 392f1be 29bcc71 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | import api from './client'
export const fetcher = url => api.get(url).then(res => res.data)
// ββ Auth ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const authAPI = {
register: (data) => api.post('/auth/register', data),
login: (data) => api.post('/auth/login', data),
resetPassword: (data) => api.post('/auth/reset-password', data),
logout: () => api.post('/auth/logout'),
me: () => api.get('/auth/me'),
}
// ββ Admin βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const adminAPI = {
getUsers: () => api.get('/admin/users'),
updateRole: (id, role) => api.patch(`/admin/users/${id}/role`, { role }),
toggleStatus: (id) => api.patch(`/admin/users/${id}/status`),
createPasswordReset: (id) => api.post(`/admin/users/${id}/password-reset`),
getTests: () => api.get('/admin/tests'),
getTest: (id) => api.get(`/admin/tests/${id}`),
createTest: (data) => api.post('/admin/tests', data),
deleteTest: (id) => api.delete(`/admin/tests/${id}`),
updateTest: (id, data) => api.patch(`/admin/tests/${id}`, data),
getQuestions: (testId) => api.get(`/admin/tests/${testId}/questions`),
addQuestions: (testId, qs) => api.post(`/admin/tests/${testId}/questions`, { questions: qs }),
updateQuestion: (testId, qId, data) => api.patch(`/admin/tests/${testId}/questions/${qId}`, data),
uploadQuestionsFile: (testId, form) => api.post(`/admin/tests/${testId}/questions/upload-file`, form, { headers: { 'Content-Type': 'multipart/form-data' } }),
deleteQuestion: (testId, qId) => api.delete(`/admin/tests/${testId}/questions/${qId}`),
uploadQImage: (qId, form, target = 'question') => api.post(`/admin/questions/${qId}/image?target=${encodeURIComponent(target)}`, form, { headers: { 'Content-Type': 'multipart/form-data' } }),
deleteQImage: (qId, target) => api.delete(`/admin/questions/${qId}/image?target=${encodeURIComponent(target)}`),
}
// ββ Tests βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const testAPI = {
getTests: () => api.get('/tests'),
getTest: (id) => api.get(`/tests/${id}`),
startTest: (id) => api.post(`/tests/${id}/start`),
getQuestions: (testId, attemptId) => api.get(`/tests/${testId}/attempt/${attemptId}/questions`),
saveAnswers: (testId, attemptId, ans) => api.post(`/tests/${testId}/attempt/${attemptId}/save`, { answers: ans }),
submitTest: (testId, attemptId, ans) => api.post(`/tests/${testId}/attempt/${attemptId}/submit`, { answers: ans }),
updateViolations: (testId, attemptId, data) => api.patch(`/tests/${testId}/attempt/${attemptId}/violations`, data),
getResult: (attemptId) => api.get(`/tests/attempt/${attemptId}/result`),
downloadResultHtml: (attemptId) => api.get(`/tests/attempt/${attemptId}/result.html`, { responseType: 'blob' }),
getHistory: () => api.get('/tests/my/history'),
getLeaderboard: (testId) => api.get(`/tests/${testId}/leaderboard`),
getMyAttempts: (testId) => api.get(`/tests/${testId}/my-attempts`),
}
// ββ Bookmarks βββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const bookmarkAPI = {
toggle: (questionId, note) => api.post(`/bookmarks/${questionId}/toggle`, { note }),
getAll: () => api.get('/bookmarks'),
getIds: () => api.get('/bookmarks/ids'),
updateNote: (questionId, note) => api.patch(`/bookmarks/${questionId}/note`, { note }),
}
// ββ Series ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const seriesAPI = {
getAll: () => api.get('/series'),
getTests: (id) => api.get(`/series/${id}/tests`),
create: (data) => api.post('/series', data),
delete: (id) => api.delete(`/series/${id}`),
}
|