78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
import { useMutation, useQuery } from '@tanstack/vue-query'
|
|
|
|
import {
|
|
apiAddAdminExam,
|
|
apiDeleteAdminExam,
|
|
apiGetAdminExams,
|
|
apiGetAdminExamParticipants,
|
|
apiShowAdminExam,
|
|
apiShowAdminExamParticipant,
|
|
apiUpdateAdminExam,
|
|
} from '@/services/api/admin-exams'
|
|
import { cleanFilters } from '@/utils/clean-filters'
|
|
|
|
export const adminExamsKeys = {
|
|
all: ['admin', 'exams'],
|
|
list: (filters, pagination) => ['admin', 'exams', 'list', filters, pagination],
|
|
detail: (id) => ['admin', 'exams', 'detail', id],
|
|
participants: (examId, filters, pagination) => [
|
|
'admin',
|
|
'exams',
|
|
'participants',
|
|
examId,
|
|
filters,
|
|
pagination,
|
|
],
|
|
participantDetail: (examId, participantId) => [
|
|
'admin',
|
|
'exams',
|
|
'participants',
|
|
examId,
|
|
'detail',
|
|
participantId,
|
|
],
|
|
}
|
|
|
|
export const useAdminExamsListQuery = (filtersRef, paginationRef, options = {}) =>
|
|
useQuery({
|
|
queryKey: ['admin', 'exams', 'list', filtersRef, paginationRef],
|
|
queryFn: () => apiGetAdminExams({ ...cleanFilters(filtersRef.value), ...paginationRef.value }),
|
|
...options,
|
|
})
|
|
|
|
export const useAdminExamQuery = (idRef, options = {}) =>
|
|
useQuery({
|
|
queryKey: ['admin', 'exams', 'detail', idRef],
|
|
queryFn: () => apiShowAdminExam(idRef.value),
|
|
select: (response) => response?.data ?? response,
|
|
...options,
|
|
})
|
|
|
|
export const useAdminExamParticipantsQuery = (examIdRef, filtersRef, paginationRef, options = {}) =>
|
|
useQuery({
|
|
queryKey: ['admin', 'exams', 'participants', examIdRef, filtersRef, paginationRef],
|
|
queryFn: () =>
|
|
apiGetAdminExamParticipants(examIdRef.value, {
|
|
...cleanFilters(filtersRef?.value || {}),
|
|
...paginationRef?.value,
|
|
}),
|
|
...options,
|
|
})
|
|
|
|
export const useAdminExamParticipantQuery = (examIdRef, participantIdRef, options = {}) =>
|
|
useQuery({
|
|
queryKey: ['admin', 'exams', 'participants', examIdRef, 'detail', participantIdRef],
|
|
queryFn: () => apiShowAdminExamParticipant(examIdRef.value, participantIdRef.value),
|
|
select: (response) => response?.data ?? response,
|
|
...options,
|
|
})
|
|
|
|
export const useAddAdminExamMutation = () =>
|
|
useMutation({ mutationFn: (payload) => apiAddAdminExam(payload) })
|
|
|
|
export const useUpdateAdminExamMutation = () =>
|
|
useMutation({ mutationFn: ({ id, payload }) => apiUpdateAdminExam(id, payload) })
|
|
|
|
export const useDeleteAdminExamMutation = () =>
|
|
useMutation({ mutationFn: (id) => apiDeleteAdminExam(id) })
|