ENCOA-315
This commit is contained in:
27
src/utils/disabled.be.ts
Normal file
27
src/utils/disabled.be.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import client from "@/lib/mongodb";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
async function getPendingEvals(userId: string): Promise<string[]> {
|
||||
try {
|
||||
const disabledStatsSessions = await db.collection("stats")
|
||||
.distinct("session", {
|
||||
"isDisabled": true,
|
||||
"user": userId
|
||||
});
|
||||
|
||||
const sessionsWithEvals = await db.collection("evaluation")
|
||||
.distinct("session_id", {
|
||||
"session_id": { $in: disabledStatsSessions },
|
||||
"user": userId
|
||||
});
|
||||
|
||||
|
||||
return sessionsWithEvals;
|
||||
} catch (error) {
|
||||
console.error('Error fetching session IDs:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export default getPendingEvals;
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
WritingExercise,
|
||||
} from "@/interfaces/exam";
|
||||
import axios from "axios";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const evaluateWritingAnswer = async (
|
||||
userId: string,
|
||||
@@ -13,7 +14,7 @@ export const evaluateWritingAnswer = async (
|
||||
task: number,
|
||||
solution: UserSolution,
|
||||
attachment?: string,
|
||||
): Promise<void> => {
|
||||
): Promise<UserSolution> => {
|
||||
await axios.post("/api/evaluate/writing", {
|
||||
question: `${exercise.prompt}`.replaceAll("\n", ""),
|
||||
answer: solution.solutions[0].solution.trim().replaceAll("\n", " "),
|
||||
@@ -23,6 +24,18 @@ export const evaluateWritingAnswer = async (
|
||||
exerciseId: exercise.id,
|
||||
attachment,
|
||||
});
|
||||
|
||||
return {
|
||||
...solution,
|
||||
id: v4(),
|
||||
score: {
|
||||
correct: 0,
|
||||
missing: 0,
|
||||
total: 100,
|
||||
},
|
||||
solutions: [{id: exercise.id, solution: solution.solutions[0].solution}],
|
||||
isDisabled: true,
|
||||
};
|
||||
};
|
||||
|
||||
export const evaluateSpeakingAnswer = async (
|
||||
@@ -31,12 +44,12 @@ export const evaluateSpeakingAnswer = async (
|
||||
exercise: SpeakingExercise | InteractiveSpeakingExercise,
|
||||
solution: UserSolution,
|
||||
task: number,
|
||||
): Promise<void> => {
|
||||
): Promise<UserSolution> => {
|
||||
switch (exercise?.type) {
|
||||
case "speaking":
|
||||
await evaluateSpeakingExercise(userId, sessionId, exercise, solution);
|
||||
return await evaluateSpeakingExercise(userId, sessionId, exercise, solution);
|
||||
case "interactiveSpeaking":
|
||||
await evaluateInteractiveSpeakingExercise(userId, sessionId, exercise.id, solution, task);
|
||||
return await evaluateInteractiveSpeakingExercise(userId, sessionId, exercise.id, solution, task);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,7 +63,7 @@ const evaluateSpeakingExercise = async (
|
||||
sessionId: string,
|
||||
exercise: SpeakingExercise,
|
||||
solution: UserSolution,
|
||||
): Promise<void> => {
|
||||
): Promise<UserSolution> => {
|
||||
const formData = new FormData();
|
||||
|
||||
const url = solution.solutions[0].solution.trim() as string;
|
||||
@@ -76,6 +89,17 @@ const evaluateSpeakingExercise = async (
|
||||
};
|
||||
|
||||
await axios.post(`/api/evaluate/speaking`, formData, config);
|
||||
return {
|
||||
...solution,
|
||||
id: v4(),
|
||||
score: {
|
||||
correct: 0,
|
||||
missing: 0,
|
||||
total: 100,
|
||||
},
|
||||
solutions: [{id: exercise.id, solution: null}],
|
||||
isDisabled: true,
|
||||
};
|
||||
};
|
||||
|
||||
const evaluateInteractiveSpeakingExercise = async (
|
||||
@@ -84,7 +108,7 @@ const evaluateInteractiveSpeakingExercise = async (
|
||||
exerciseId: string,
|
||||
solution: UserSolution,
|
||||
task: number,
|
||||
): Promise<void> => {
|
||||
): Promise<UserSolution> => {
|
||||
const formData = new FormData();
|
||||
formData.append("userId", userId);
|
||||
formData.append("sessionId", sessionId);
|
||||
@@ -111,4 +135,15 @@ const evaluateInteractiveSpeakingExercise = async (
|
||||
};
|
||||
|
||||
await axios.post(`/api/evaluate/interactiveSpeaking`, formData, config);
|
||||
return {
|
||||
...solution,
|
||||
id: v4(),
|
||||
score: {
|
||||
correct: 0,
|
||||
missing: 0,
|
||||
total: 100,
|
||||
},
|
||||
solutions: [{id: exerciseId, solution: null}],
|
||||
isDisabled: true,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user