@@ -85,6 +85,7 @@ export const endpoints = {
|
||||
|
||||
// ─── Backend-aligned: Exams ────────────────────────────────────────────────
|
||||
getExamsList: '/admin/exams',
|
||||
getStudentExamsList: '/student/exams',
|
||||
showExam: '/exams/:id',
|
||||
addNewExam: '/exams',
|
||||
updateExam: '/exams/:id',
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { http } from '@/services/api/http'
|
||||
import { buildUrl, endpoints } from '@/services/api/endpoints'
|
||||
|
||||
export const apiGetStudentExams = (params) => http.get(endpoints.getStudentExamsList, { params })
|
||||
|
||||
export const apiShowStudentExam = (id) => http.get(buildUrl(endpoints.showExam, { id }))
|
||||
|
||||
export const apiSubmitStudentExamAttempt = (id, payload) =>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { http } from '@/services/api/http'
|
||||
import { buildUrl, endpoints } from '@/services/api/endpoints'
|
||||
|
||||
export const apiGetStudentSessions = (params) => http.get(endpoints.getSessionsList, { params })
|
||||
|
||||
export const apiShowStudentSession = (id) => http.get(buildUrl(endpoints.showSession, { id }))
|
||||
|
||||
export const apiSubmitStudentHomework = (homeworkId, payload) =>
|
||||
|
||||
@@ -10,45 +10,45 @@ export const commonKeys = {
|
||||
// Sample data so the register form is usable while the backend geo endpoints
|
||||
// are still being built. Once /provinces and /provinces/:id/cities are live,
|
||||
// the real response overwrites these and the keys stay the same.
|
||||
const SAMPLE_PROVINCES = [
|
||||
{ id: 1, name: 'تهران' },
|
||||
{ id: 2, name: 'اصفهان' },
|
||||
{ id: 3, name: 'فارس' },
|
||||
{ id: 4, name: 'خراسان رضوی' },
|
||||
{ id: 5, name: 'قم' },
|
||||
]
|
||||
// const SAMPLE_PROVINCES = [
|
||||
// { id: 1, name: 'تهران' },
|
||||
// { id: 2, name: 'اصفهان' },
|
||||
// { id: 3, name: 'فارس' },
|
||||
// { id: 4, name: 'خراسان رضوی' },
|
||||
// { id: 5, name: 'قم' },
|
||||
// ]
|
||||
|
||||
const SAMPLE_CITIES_BY_PROVINCE = {
|
||||
1: [
|
||||
{ id: 101, name: 'تهران' },
|
||||
{ id: 102, name: 'ری' },
|
||||
{ id: 103, name: 'شمیرانات' },
|
||||
{ id: 104, name: 'اسلامشهر' },
|
||||
],
|
||||
2: [
|
||||
{ id: 201, name: 'اصفهان' },
|
||||
{ id: 202, name: 'کاشان' },
|
||||
{ id: 203, name: 'نجفآباد' },
|
||||
],
|
||||
3: [
|
||||
{ id: 301, name: 'شیراز' },
|
||||
{ id: 302, name: 'مرودشت' },
|
||||
{ id: 303, name: 'کازرون' },
|
||||
],
|
||||
4: [
|
||||
{ id: 401, name: 'مشهد' },
|
||||
{ id: 402, name: 'نیشابور' },
|
||||
{ id: 403, name: 'سبزوار' },
|
||||
],
|
||||
5: [{ id: 501, name: 'قم' }],
|
||||
}
|
||||
// const SAMPLE_CITIES_BY_PROVINCE = {
|
||||
// 1: [
|
||||
// { id: 101, name: 'تهران' },
|
||||
// { id: 102, name: 'ری' },
|
||||
// { id: 103, name: 'شمیرانات' },
|
||||
// { id: 104, name: 'اسلامشهر' },
|
||||
// ],
|
||||
// 2: [
|
||||
// { id: 201, name: 'اصفهان' },
|
||||
// { id: 202, name: 'کاشان' },
|
||||
// { id: 203, name: 'نجفآباد' },
|
||||
// ],
|
||||
// 3: [
|
||||
// { id: 301, name: 'شیراز' },
|
||||
// { id: 302, name: 'مرودشت' },
|
||||
// { id: 303, name: 'کازرون' },
|
||||
// ],
|
||||
// 4: [
|
||||
// { id: 401, name: 'مشهد' },
|
||||
// { id: 402, name: 'نیشابور' },
|
||||
// { id: 403, name: 'سبزوار' },
|
||||
// ],
|
||||
// 5: [{ id: 501, name: 'قم' }],
|
||||
// }
|
||||
|
||||
export const useGetProvincesQuery = (options = {}) =>
|
||||
useQuery({
|
||||
queryKey: commonKeys.provinces(),
|
||||
queryFn: () => apiGetProvinces(),
|
||||
select: (response) => response?.data ?? response,
|
||||
initialData: SAMPLE_PROVINCES,
|
||||
// initialData: SAMPLE_PROVINCES,
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -57,6 +57,6 @@ export const useGetCitiesOfProvinceQuery = (provinceIdRef, options = {}) =>
|
||||
queryKey: ['common', 'cities', provinceIdRef],
|
||||
queryFn: () => apiGetCitiesOfProvince(provinceIdRef.value),
|
||||
select: (response) => response?.data ?? response,
|
||||
initialData: () => SAMPLE_CITIES_BY_PROVINCE[provinceIdRef.value] || [],
|
||||
// initialData: () => SAMPLE_CITIES_BY_PROVINCE[provinceIdRef.value] || [],
|
||||
...options,
|
||||
})
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
import { cleanFilters } from '@/utils/clean-filters'
|
||||
import { useMutation, useQuery } from '@tanstack/vue-query'
|
||||
import { apiShowStudentExam, apiSubmitStudentExamAttempt } from '@/services/api/student-exams'
|
||||
import {
|
||||
apiGetStudentExams,
|
||||
apiShowStudentExam,
|
||||
apiSubmitStudentExamAttempt,
|
||||
} from '@/services/api/student-exams'
|
||||
|
||||
export const studentExamsKeys = {
|
||||
list: (filters, pagination) => ['student', 'exams', 'list', filters, pagination],
|
||||
detail: (id) => ['student', 'exams', 'detail', id],
|
||||
}
|
||||
|
||||
export const useStudentExamsListQuery = (filtersRef, paginationRef, options = {}) =>
|
||||
useQuery({
|
||||
queryKey: ['student', 'exams', 'list', filtersRef, paginationRef],
|
||||
queryFn: () =>
|
||||
apiGetStudentExams({
|
||||
...cleanFilters(filtersRef.value),
|
||||
...paginationRef.value,
|
||||
}),
|
||||
select: (response) => ({
|
||||
data: response?.data?.items ?? response?.data ?? [],
|
||||
meta: response?.data?.meta ?? response?.meta,
|
||||
}),
|
||||
...options,
|
||||
})
|
||||
|
||||
export const useStudentExamQuery = (idRef, options = {}) =>
|
||||
useQuery({
|
||||
queryKey: ['student', 'exams', 'detail', idRef],
|
||||
|
||||
@@ -1,19 +1,40 @@
|
||||
import { cleanFilters } from '@/utils/clean-filters'
|
||||
import { useMutation, useQuery } from '@tanstack/vue-query'
|
||||
import { apiShowStudentSession, apiSubmitStudentHomework } from '@/services/api/student-sessions'
|
||||
import {
|
||||
apiGetStudentSessions,
|
||||
apiShowStudentSession,
|
||||
apiSubmitStudentHomework,
|
||||
} from '@/services/api/student-sessions'
|
||||
|
||||
export const studentSessionsKeys = {
|
||||
list: (filters, pagination) => ['student', 'sessions', 'list', filters, pagination],
|
||||
detail: (id) => ['student', 'sessions', 'detail', id],
|
||||
}
|
||||
|
||||
export const useStudentSessionsListQuery = (filtersRef, paginationRef, options = {}) =>
|
||||
useQuery({
|
||||
queryKey: ['student', 'sessions', 'list', filtersRef, paginationRef],
|
||||
queryFn: () =>
|
||||
apiGetStudentSessions({
|
||||
...cleanFilters(filtersRef.value),
|
||||
...paginationRef.value,
|
||||
}),
|
||||
select: (response) => ({
|
||||
data: response?.data?.items ?? response?.data ?? [],
|
||||
meta: response?.data?.meta ?? response?.meta,
|
||||
}),
|
||||
...options,
|
||||
})
|
||||
|
||||
const adaptSessionResponse = (response) => {
|
||||
const session = response?.data ?? response ?? {}
|
||||
const media = Array.isArray(session.media) ? session.media : []
|
||||
const byCollection = (name) => media.find((m) => m.collectionName === name)
|
||||
return {
|
||||
...session,
|
||||
videoUrl: byCollection('videos')?.url ?? null,
|
||||
audioUrl: byCollection('voices')?.url ?? null,
|
||||
pdfUrl: byCollection('pdfs')?.url ?? null,
|
||||
videoUrl: byCollection('video')?.url ?? null,
|
||||
audioUrl: byCollection('voice')?.downloadUrl ?? null,
|
||||
pdfUrl: byCollection('pdf')?.url ?? null,
|
||||
poster: byCollection('cover')?.url ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user