feat: POST /corrections/eo — Gemini transcription + DeepSeek EO — 84/84 tests
This commit is contained in:
parent
77d5a8373e
commit
f4f8c55ce7
7 changed files with 422 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { supabase } from '../lib/supabase'
|
||||
import { correctEE as deepseekCorrectEE } from '../lib/deepseek'
|
||||
import type { EERapport } from '../lib/deepseek'
|
||||
import { correctEE as deepseekCorrectEE, correctEO as deepseekCorrectEO } from '../lib/deepseek'
|
||||
import type { EERapport, EORapport } from '../lib/deepseek'
|
||||
import type { AuthProfile } from '../middleware/auth'
|
||||
|
||||
type CorrectionError = {
|
||||
|
|
@ -76,3 +76,71 @@ export async function correctEE(
|
|||
// 4. Retourner le rapport complet
|
||||
return { data: rapport }
|
||||
}
|
||||
|
||||
export async function correctEO(
|
||||
simulationId: string,
|
||||
transcript: string,
|
||||
tache: string,
|
||||
profile: AuthProfile
|
||||
): Promise<{ data: EORapport } | CorrectionError> {
|
||||
// 1. Vérifier que la production existe et appartient à l'utilisateur
|
||||
const { data: production, error: fetchError } = await supabase
|
||||
.from('productions')
|
||||
.select('id, user_id, tache')
|
||||
.eq('id', simulationId)
|
||||
.single()
|
||||
|
||||
if (fetchError || !production) {
|
||||
return {
|
||||
error: true,
|
||||
code: 'SIMULATION_NOT_FOUND',
|
||||
message: 'Simulation introuvable.',
|
||||
status: 404,
|
||||
}
|
||||
}
|
||||
|
||||
if (production.user_id !== profile.id) {
|
||||
return {
|
||||
error: true,
|
||||
code: 'AUTH_REQUIRED',
|
||||
message: 'Cette simulation ne vous appartient pas.',
|
||||
status: 401,
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Appeler DeepSeek pour la correction EO
|
||||
let rapport: EORapport
|
||||
try {
|
||||
rapport = await deepseekCorrectEO(transcript, tache)
|
||||
} catch {
|
||||
return {
|
||||
error: true,
|
||||
code: 'INTERNAL_ERROR',
|
||||
message: 'Erreur lors de la correction. Veuillez réessayer dans quelques instants.',
|
||||
status: 500,
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Mettre à jour la production dans Supabase
|
||||
const { error: updateError } = await supabase
|
||||
.from('productions')
|
||||
.update({
|
||||
contenu: transcript,
|
||||
score: rapport.score,
|
||||
nclc: rapport.nclc,
|
||||
rapport: JSON.stringify(rapport),
|
||||
})
|
||||
.eq('id', simulationId)
|
||||
|
||||
if (updateError) {
|
||||
return {
|
||||
error: true,
|
||||
code: 'INTERNAL_ERROR',
|
||||
message: 'Erreur lors de la sauvegarde du rapport. Veuillez réessayer.',
|
||||
status: 500,
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Retourner le rapport complet
|
||||
return { data: rapport }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue