Unfinished grading attempt at solving it
This commit is contained in:
@@ -6,6 +6,9 @@ import axios from "axios";
|
||||
import formidable from "formidable-serverless";
|
||||
import fs from "fs";
|
||||
import FormData from 'form-data';
|
||||
import client from "@/lib/mongodb";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
@@ -41,6 +44,34 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
formData.append('audio_1', buffer, 'audio_1.wav');
|
||||
fs.rmSync(audioFile.path);
|
||||
|
||||
// Check if there is one eval for the current exercise
|
||||
const previousEval = await db.collection("evaluation").findOne({
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
})
|
||||
|
||||
// If there is delete it
|
||||
if (previousEval) {
|
||||
await db.collection("evaluation").deleteOne({
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
})
|
||||
}
|
||||
|
||||
// Insert the new eval for the backend to place it's result
|
||||
await db.collection("evaluation").insertOne(
|
||||
{
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
type: "speaking",
|
||||
task: 2,
|
||||
status: "pending"
|
||||
}
|
||||
);
|
||||
|
||||
await axios.post(
|
||||
`${process.env.BACKEND_URL}/grade/speaking/2`,
|
||||
formData,
|
||||
|
||||
Reference in New Issue
Block a user