fix(simulations): déplacer incrément simulations_used après correction réussie (Option B)

This commit is contained in:
Hermann_Kitio 2026-04-21 02:01:13 +03:00
parent 1a5b79807e
commit ecb478e10c
3 changed files with 23 additions and 27 deletions

View file

@ -1,5 +1,6 @@
import { supabase } from '../lib/supabase.js'
import { correctEE as deepseekCorrectEE, correctEO as deepseekCorrectEO } from '../lib/deepseek.js'
import { PLANS, type Plan } from '../lib/access.js'
import type { EERapport, EORapport } from '../lib/deepseek.js'
import type { AuthProfile } from '../middleware/auth.js'
@ -73,7 +74,15 @@ export async function correctEE(
}
}
// 4. Retourner le rapport complet enrichi avec simulation_id
// 4. Incrémenter simulations_used si le plan a une limite (non bloquant).
if (PLANS[profile.plan as Plan].simulations_lifetime !== null) {
await supabase
.from('profiles')
.update({ simulations_used: profile.simulations_used + 1 })
.eq('id', profile.id)
}
// 5. Retourner le rapport complet enrichi avec simulation_id
return { data: { ...rapport, simulation_id: simulationId } }
}
@ -141,6 +150,14 @@ export async function correctEO(
}
}
// 4. Retourner le rapport complet enrichi avec simulation_id
// 4. Incrémenter simulations_used si le plan a une limite (non bloquant).
if (PLANS[profile.plan as Plan].simulations_lifetime !== null) {
await supabase
.from('profiles')
.update({ simulations_used: profile.simulations_used + 1 })
.eq('id', profile.id)
}
// 5. Retourner le rapport complet enrichi avec simulation_id
return { data: { ...rapport, simulation_id: simulationId } }
}