feat(simulations): GET /simulations — liste paginée des productions (Sprint 3.7)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hermann_Kitio 2026-04-22 20:54:36 +03:00
parent 14d8d73991
commit a394ce8429
3 changed files with 357 additions and 0 deletions

View file

@ -131,6 +131,78 @@ export async function create(
}
}
// Sprint 3.7 — liste paginée des productions de l'utilisateur connecté.
// Renvoie uniquement les champs utiles à l'affichage en liste (pas de contenu,
// rapport, exercices, modele — trop lourds).
export interface ListOptions {
page: number
limit: number
}
export interface ListItem {
id: string
tache: Tache
mode: Mode
score: number | null
nclc: number | null
nclc_cible: 9 | 10 | null
created_at: string
}
export interface ListResult {
data: ListItem[]
pagination: {
page: number
limit: number
total: number
}
}
type ListError = ControllerError
export async function list(
options: ListOptions,
profile: AuthProfile,
): Promise<{ data: ListResult } | ListError> {
const { page, limit } = options
const offset = (page - 1) * limit
const { data, error, count } = await supabase
.from('productions')
.select('id, tache, mode, score, nclc, nclc_cible, created_at', { count: 'exact' })
.eq('user_id', profile.id)
.order('created_at', { ascending: false })
.range(offset, offset + limit - 1)
if (error) {
return {
error: true,
code: 'INTERNAL_ERROR',
message: 'Impossible de charger les simulations.',
status: 500,
}
}
const items: ListItem[] = (data ?? []).map((row) => ({
id: row.id as string,
tache: row.tache as Tache,
mode: row.mode as Mode,
score: (row.score as number | null) ?? null,
nclc: (row.nclc as number | null) ?? null,
nclc_cible:
row.nclc_cible === 9 || row.nclc_cible === 10 ? (row.nclc_cible as 9 | 10) : null,
created_at: row.created_at as string,
}))
return {
data: {
data: items,
pagination: { page, limit, total: count ?? 0 },
},
}
}
// Sprint 3.6a — structure enrichie (revelation, diagnostic, conseil_nclc,
// erreurs_codes) + statuts des jobs asynchrones (modele, exercices).
//