fix [P-227]: прохождение теста
This commit is contained in:
1 parent
4a45452345
commit
de2bf176d0
1 file changed
+55
-3
@@ -70,10 +70,35 @@ export default {
|
|||||||
const currentQuestion = ref(0);
|
const currentQuestion = ref(0);
|
||||||
let timer = null;
|
let timer = null;
|
||||||
const data = ref(null);
|
const data = ref(null);
|
||||||
|
const testingId = ref(null);
|
||||||
|
|
||||||
const getTestById = async (id) => {
|
const getTestById = async (id) => {
|
||||||
const resp = await axiosApiInstance.get(`/api/tests/testdetail/${id}`);
|
const resp = await axiosApiInstance.get(`/api/tests/testdetail/${id}`);
|
||||||
data.value = resp.data;
|
data.value = resp.data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const testingResp = await axiosApiInstance.get(`/api/tests/testingview/?test_id=${id}`);
|
||||||
|
const userTestings = testingResp.data;
|
||||||
|
if (userTestings?.length > 0) {
|
||||||
|
const testMode = route.query.mode;
|
||||||
|
const isFormalTesting = testMode === 'exam' || testMode === 'retry';
|
||||||
|
|
||||||
|
const sortedTestings = [...userTestings].sort((a, b) => {
|
||||||
|
return new Date(b.completion_date) - new Date(a.completion_date);
|
||||||
|
});
|
||||||
|
|
||||||
|
const activeTestings = sortedTestings.filter(t =>
|
||||||
|
isFormalTesting ? !t.completed : true
|
||||||
|
);
|
||||||
|
if (activeTestings.length > 0) {
|
||||||
|
testingId.value = activeTestings[0].id;
|
||||||
|
} else if (sortedTestings.length > 0) {
|
||||||
|
testingId.value = sortedTestings[0].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error getting testing record:', error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const formattedTime = computed(() => {
|
const formattedTime = computed(() => {
|
||||||
@@ -88,7 +113,30 @@ export default {
|
|||||||
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const startTest = () => {
|
const deactivateOldTestings = async (testId) => {
|
||||||
|
try {
|
||||||
|
const testingResp = await axiosApiInstance.get(`/api/tests/testingview/?test_id=${testId}`);
|
||||||
|
const userTestings = testingResp.data;
|
||||||
|
|
||||||
|
if (userTestings?.length > 1) {
|
||||||
|
const sortedTestings = [...userTestings].sort((a, b) => {
|
||||||
|
return new Date(b.completion_date) - new Date(a.completion_date);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i = 1; i < sortedTestings.length; i++) {
|
||||||
|
await axiosApiInstance.delete(`/api/tests/testingview/`, {
|
||||||
|
data: { id: sortedTestings[i].id }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deactivating old testings:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const startTest = async () => {
|
||||||
|
await deactivateOldTestings(testId);
|
||||||
|
|
||||||
testStarted.value = true;
|
testStarted.value = true;
|
||||||
testFinished.value = false;
|
testFinished.value = false;
|
||||||
|
|
||||||
@@ -135,14 +183,18 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const testMode = route.query.mode;
|
const testMode = route.query.mode;
|
||||||
|
|
||||||
const isFormalTesting = testMode === 'exam' || testMode === 'retry';
|
const isFormalTesting = testMode === 'exam' || testMode === 'retry';
|
||||||
|
|
||||||
console.log('Отправляем результаты теста:', answersToSubmit);
|
console.log('Отправляем результаты теста:', answersToSubmit);
|
||||||
console.log('Режим тестирования:', isFormalTesting ? 'testing' : 'practice');
|
console.log('Режим тестирования:', isFormalTesting ? 'testing' : 'practice');
|
||||||
|
|
||||||
|
const queryParams = new URLSearchParams();
|
||||||
|
if (isFormalTesting) {
|
||||||
|
queryParams.append('status', 'testing');
|
||||||
|
}
|
||||||
|
|
||||||
await axiosApiInstance.post(
|
await axiosApiInstance.post(
|
||||||
`/api/tests/testresultview/?status=${isFormalTesting ? 'testing' : ''}`,
|
`/api/tests/testresultview/?${queryParams.toString()}`,
|
||||||
answersToSubmit,
|
answersToSubmit,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user