From 4245d0bcf1fc0a712dcc58fd06236ec583edb134 Mon Sep 17 00:00:00 2001 From: Hermann_Kitio Date: Tue, 21 Apr 2026 01:07:30 +0300 Subject: [PATCH] =?UTF-8?q?feat(production):=20getSujets()=20=E2=80=94=20G?= =?UTF-8?q?ET=20/sujets=3Fmode=3D&tache=3D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/production/api.ts | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/entities/production/api.ts b/src/entities/production/api.ts index 1036abc..a7ea0b0 100644 --- a/src/entities/production/api.ts +++ b/src/entities/production/api.ts @@ -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 { @@ -20,3 +20,38 @@ export function createSimulation(payload: CreateSimulationPayload): Promise { return apiFetch(`/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 { + 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) +}