feat(simulations): resume session + RapportPage tolère rapport=null (FTD-21)

This commit is contained in:
Hermann_Kitio 2026-04-21 04:52:51 +03:00
parent aaecc3f804
commit ae8d8af1df
2 changed files with 48 additions and 5 deletions

View file

@ -11,11 +11,28 @@
*/
import { apiFetch } from '@/shared/lib/api-client'
import { getSimulationState } from '@/entities/production/api'
import type { CorrectEePayload, CorrectEoPayload, Report } from './types'
/** Récupère un rapport existant. Endpoint : `GET /simulations/:id`. */
/**
* Récupère un rapport existant. Endpoint : `GET /simulations/:id`.
*
* FTD-21 : depuis l'assouplissement de `getById` côté backend (tolère `rapport=null`
* pour permettre le resume), on unwrap le champ `rapport` du `SimulationState`.
* Si la simulation est encore en cours (`rapport === null`), on lève une erreur
* typée `REPORT_NOT_READY` que RapportPage catche pour rediriger vers /simulation/ee.
*/
export function getReport(id: string): Promise<Report> {
return apiFetch<Report>(`/simulations/${id}`)
return getSimulationState(id).then((state) => {
if (state.rapport === null) {
throw {
error: true,
code: 'REPORT_NOT_READY',
message: 'Simulation en cours — rédaction pas encore corrigée.',
}
}
return { ...state.rapport, simulation_id: state.simulation_id }
})
}
const CORRECTION_TIMEOUT_MS = 30_000