feat(simulations): resume session + RapportPage tolère rapport=null (FTD-21)
This commit is contained in:
parent
aaecc3f804
commit
ae8d8af1df
2 changed files with 48 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue