feat(production): getSujets() — GET /sujets?mode=&tache=
This commit is contained in:
parent
021b9d35ea
commit
4245d0bcf1
1 changed files with 36 additions and 1 deletions
|
|
@ -9,7 +9,7 @@
|
|||
*/
|
||||
|
||||
import { apiFetch } from '@/shared/lib/api-client'
|
||||
import type { CreateSimulationPayload, Production } from './types'
|
||||
import type { CreateSimulationPayload, Production, SujetData, Tache } from './types'
|
||||
|
||||
/** Crée une nouvelle simulation. Endpoint : `POST /simulations` (HTTP 201). */
|
||||
export function createSimulation(payload: CreateSimulationPayload): Promise<Production> {
|
||||
|
|
@ -20,3 +20,38 @@ export function createSimulation(payload: CreateSimulationPayload): Promise<Prod
|
|||
export function getSimulation(id: string): Promise<Production> {
|
||||
return apiFetch<Production>(`/simulations/${id}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Mappe une Tache vers les paramètres de la route `GET /sujets`.
|
||||
* Retourne `null` pour les tâches sans catalogue de sujets côté base
|
||||
* (EO_T1 : sujet fixe connu, EO_T2_LIVE : interaction sans sujet).
|
||||
*/
|
||||
function mapTacheToSujetParams(
|
||||
tache: Tache,
|
||||
): { mode: 'EE' | 'EO'; tacheNumber: 1 | 2 | 3 } | null {
|
||||
switch (tache) {
|
||||
case 'EE_T1':
|
||||
return { mode: 'EE', tacheNumber: 1 }
|
||||
case 'EE_T2':
|
||||
return { mode: 'EE', tacheNumber: 2 }
|
||||
case 'EE_T3':
|
||||
return { mode: 'EE', tacheNumber: 3 }
|
||||
case 'EO_T3':
|
||||
return { mode: 'EO', tacheNumber: 3 }
|
||||
case 'EO_T1':
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la liste des sujets actifs disponibles pour une tâche.
|
||||
* Endpoint : `GET /sujets?mode=XX&tache=N`.
|
||||
*
|
||||
* Retourne `[]` immédiatement pour les tâches sans catalogue (EO_T1).
|
||||
*/
|
||||
export function getSujets(tache: Tache): Promise<SujetData[]> {
|
||||
const params = mapTacheToSujetParams(tache)
|
||||
if (!params) return Promise.resolve([])
|
||||
const qs = new URLSearchParams({ mode: params.mode, tache: String(params.tacheNumber) })
|
||||
return apiFetch<{ sujets: SujetData[] }>(`/sujets?${qs.toString()}`).then((r) => r.sujets)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue