feat: POST /corrections/ee — DeepSeek rapport complet — 73/73 tests

This commit is contained in:
Hermann_Kitio 2026-04-16 17:14:45 +03:00
parent a6ee76d4a8
commit 77d5a8373e
6 changed files with 385 additions and 23 deletions

View file

@ -0,0 +1,78 @@
import { supabase } from '../lib/supabase'
import { correctEE as deepseekCorrectEE } from '../lib/deepseek'
import type { EERapport } from '../lib/deepseek'
import type { AuthProfile } from '../middleware/auth'
type CorrectionError = {
error: true
code: string
message: string
status: number
}
export async function correctEE(
simulationId: string,
contenu: string,
tache: string,
profile: AuthProfile
): Promise<{ data: EERapport } | 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
let rapport: EERapport
try {
rapport = await deepseekCorrectEE(contenu, 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({
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 }
}