feat: Permettre l'import d'enseignants via fichier CSV ou XLSX
L'établissement a besoin d'importer en masse ses enseignants depuis les exports des logiciels de vie scolaire (Pronote, EDT, etc.), comme c'est déjà possible pour les élèves. Le wizard en 4 étapes (upload → mapping → aperçu → import) réutilise l'architecture de l'import élèves tout en ajoutant la gestion des matières et des classes enseignées. Corrections de la review #2 intégrées : - La commande ImportTeachersCommand est routée en async via Messenger pour ne pas bloquer la requête HTTP sur les gros fichiers. - Le handler est protégé par un try/catch Throwable pour marquer le batch en échec si une erreur inattendue survient, évitant qu'il reste bloqué en statut "processing". - Les domain events (UtilisateurInvite) sont dispatchés sur l'event bus après chaque création d'utilisateur, déclenchant l'envoi des emails d'invitation. - L'option "mettre à jour les enseignants existants" (AC5) permet de choisir entre ignorer ou mettre à jour nom/prénom et ajouter les affectations manquantes pour les doublons détectés par email.
This commit is contained in:
@@ -81,11 +81,16 @@
|
||||
<span class="action-label">Identité visuelle</span>
|
||||
<span class="action-hint">Logo et couleurs</span>
|
||||
</a>
|
||||
<div class="action-card disabled" aria-disabled="true">
|
||||
<a class="action-card" href="/admin/import/students">
|
||||
<span class="action-icon">📤</span>
|
||||
<span class="action-label">Importer des données</span>
|
||||
<span class="action-hint">Bientôt disponible</span>
|
||||
</div>
|
||||
<span class="action-label">Importer des élèves</span>
|
||||
<span class="action-hint">CSV ou XLSX</span>
|
||||
</a>
|
||||
<a class="action-card" href="/admin/import/teachers">
|
||||
<span class="action-icon">📤</span>
|
||||
<span class="action-label">Importer des enseignants</span>
|
||||
<span class="action-hint">CSV ou XLSX</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -198,18 +203,13 @@
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.action-card:not(.disabled):hover {
|
||||
.action-card:hover {
|
||||
border-color: #3b82f6;
|
||||
background: #eff6ff;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.action-card.disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
187
frontend/src/lib/features/import/api/teacherImport.ts
Normal file
187
frontend/src/lib/features/import/api/teacherImport.ts
Normal file
@@ -0,0 +1,187 @@
|
||||
import { getApiBaseUrl } from '$lib/api';
|
||||
import { authenticatedFetch } from '$lib/auth';
|
||||
|
||||
// === Types ===
|
||||
|
||||
export interface UploadResult {
|
||||
id: string;
|
||||
filename: string;
|
||||
totalRows: number;
|
||||
columns: string[];
|
||||
detectedFormat: string;
|
||||
suggestedMapping: Record<string, string>;
|
||||
preview: PreviewRow[];
|
||||
}
|
||||
|
||||
export interface PreviewRow {
|
||||
line: number;
|
||||
data: Record<string, string>;
|
||||
valid: boolean;
|
||||
errors: RowError[];
|
||||
}
|
||||
|
||||
export interface RowError {
|
||||
column: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface MappingResult {
|
||||
id: string;
|
||||
mapping: Record<string, string>;
|
||||
totalRows: number;
|
||||
}
|
||||
|
||||
export interface PreviewResult {
|
||||
id: string;
|
||||
totalRows: number;
|
||||
validCount: number;
|
||||
errorCount: number;
|
||||
rows: PreviewRow[];
|
||||
unknownSubjects: string[];
|
||||
unknownClasses: string[];
|
||||
}
|
||||
|
||||
export interface ConfirmResult {
|
||||
id: string;
|
||||
status: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ImportStatus {
|
||||
id: string;
|
||||
status: 'pending' | 'processing' | 'completed' | 'failed';
|
||||
totalRows: number;
|
||||
importedCount: number;
|
||||
errorCount: number;
|
||||
progression: number;
|
||||
completedAt: string | null;
|
||||
}
|
||||
|
||||
export interface ImportReport {
|
||||
id: string;
|
||||
status: string;
|
||||
totalRows: number;
|
||||
importedCount: number;
|
||||
errorCount: number;
|
||||
report: string[];
|
||||
errors: { line: number; errors: RowError[] }[];
|
||||
}
|
||||
|
||||
// === API Functions ===
|
||||
|
||||
/**
|
||||
* Upload un fichier CSV ou XLSX pour l'import d'enseignants.
|
||||
*/
|
||||
export async function uploadFile(file: File): Promise<UploadResult> {
|
||||
const apiUrl = getApiBaseUrl();
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await authenticatedFetch(`${apiUrl}/import/teachers/upload`, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => null);
|
||||
throw new Error(
|
||||
data?.['hydra:description'] ?? data?.message ?? data?.detail ?? "Erreur lors de l'upload"
|
||||
);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applique le mapping des colonnes.
|
||||
*/
|
||||
export async function applyMapping(
|
||||
batchId: string,
|
||||
mapping: Record<string, string>,
|
||||
format: string
|
||||
): Promise<MappingResult> {
|
||||
const apiUrl = getApiBaseUrl();
|
||||
const response = await authenticatedFetch(`${apiUrl}/import/teachers/${batchId}/mapping`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ mapping, format })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => null);
|
||||
throw new Error(
|
||||
data?.['hydra:description'] ?? data?.message ?? data?.detail ?? 'Erreur lors du mapping'
|
||||
);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la preview avec validation.
|
||||
*/
|
||||
export async function fetchPreview(batchId: string): Promise<PreviewResult> {
|
||||
const apiUrl = getApiBaseUrl();
|
||||
const response = await authenticatedFetch(`${apiUrl}/import/teachers/${batchId}/preview`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Erreur lors de la validation');
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirme et lance l'import.
|
||||
*/
|
||||
export async function confirmImport(
|
||||
batchId: string,
|
||||
options: { createMissingSubjects: boolean; importValidOnly: boolean; updateExisting: boolean }
|
||||
): Promise<ConfirmResult> {
|
||||
const apiUrl = getApiBaseUrl();
|
||||
const response = await authenticatedFetch(`${apiUrl}/import/teachers/${batchId}/confirm`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(options)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => null);
|
||||
throw new Error(
|
||||
data?.['hydra:description'] ??
|
||||
data?.message ??
|
||||
data?.detail ??
|
||||
'Erreur lors de la confirmation'
|
||||
);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le statut et la progression de l'import.
|
||||
*/
|
||||
export async function fetchImportStatus(batchId: string): Promise<ImportStatus> {
|
||||
const apiUrl = getApiBaseUrl();
|
||||
const response = await authenticatedFetch(`${apiUrl}/import/teachers/${batchId}/status`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Erreur lors de la récupération du statut');
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le rapport détaillé de l'import.
|
||||
*/
|
||||
export async function fetchImportReport(batchId: string): Promise<ImportReport> {
|
||||
const apiUrl = getApiBaseUrl();
|
||||
const response = await authenticatedFetch(`${apiUrl}/import/teachers/${batchId}/report`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Erreur lors de la récupération du rapport');
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
Reference in New Issue
Block a user