mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-12 08:16:09 +00:00
- API : nickname accepté à la création, à la modification et dans les propositions de contribution (trim, vide = null, 120 caractères max) - Mode direct et circuit des contributions : même validation, avant/après - Édition et ajout : champ « Surnom » facultatif - Arbre : surnom en italique sous le nom, coupé avec … au-delà de 150 px - Recherche : trouve une personne par son surnom (libellé « Surnom ») - Démo : surnoms sur Marie et Robert Vérifié : lint, tests (front 159, back 224), builds (front, back tsc, landing). Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
108 lines
2.9 KiB
JavaScript
108 lines
2.9 KiB
JavaScript
/**
|
|
* Adaptateur pour transformer les données de l'API backend
|
|
* vers le format attendu par le composant Galaxy
|
|
*/
|
|
|
|
import { t } from '../i18n/index.js'
|
|
|
|
/**
|
|
* Convertit une date ISO (YYYY-MM-DD) en année
|
|
* @param {string | null} isoDate - Date au format ISO
|
|
* @returns {number | null} - Année ou null
|
|
*/
|
|
function dateToYear(isoDate) {
|
|
if (!isoDate) return null
|
|
const year = parseInt(isoDate.split('-')[0], 10)
|
|
return isNaN(year) ? null : year
|
|
}
|
|
|
|
/**
|
|
* Détermine si une personne est vivante
|
|
* @param {string | null} deathDate - Date de décès
|
|
* @returns {boolean}
|
|
*/
|
|
function isAlive(deathDate) {
|
|
return !deathDate
|
|
}
|
|
|
|
/**
|
|
* Adapte les données du graphe API vers le format Galaxy
|
|
* @param {Object} apiGraph - Graphe depuis l'API { persons, unions, filiations, medias }
|
|
* @param {string} treeId - ID de l'arbre pour construire les URLs
|
|
* @returns {Object} - Format compatible Galaxy { persons, unions, filiations, medias }
|
|
*/
|
|
export function adaptGraphForGalaxy(apiGraph, _treeId) {
|
|
if (!apiGraph) {
|
|
return {
|
|
persons: [],
|
|
unions: [],
|
|
filiations: [],
|
|
medias: [],
|
|
}
|
|
}
|
|
|
|
const { persons = [], unions = [], filiations = [], medias = [] } = apiGraph
|
|
|
|
// Adapter les personnes
|
|
const adaptedPersons = persons.map((p) => ({
|
|
id: p.id,
|
|
firstName: p.firstName || '',
|
|
lastName: p.lastName || '',
|
|
birthName: p.birthName || null,
|
|
nickname: p.nickname || null,
|
|
birthYear: dateToYear(p.birthDate),
|
|
deathYear: dateToYear(p.deathDate),
|
|
isAlive: isAlive(p.deathDate),
|
|
sex: p.sex || null,
|
|
note: p.notes || null,
|
|
birthDate: p.birthDate,
|
|
deathDate: p.deathDate,
|
|
photo: p.avatarUrlPath ? `/api${p.avatarUrlPath}` : null,
|
|
avatarFromImmich: Boolean(p.avatarFromImmich),
|
|
frameType: 'round', // Default
|
|
}))
|
|
|
|
// Adapter les unions
|
|
const adaptedUnions = unions.map((u) => ({
|
|
id: u.id,
|
|
partner1Id: u.partner1PersonId,
|
|
partner2Id: u.partner2PersonId,
|
|
unionType: u.unionType || 'union',
|
|
startYear: dateToYear(u.startDate),
|
|
endYear: dateToYear(u.endDate),
|
|
displayOrder: u.displayOrder,
|
|
startDate: u.startDate,
|
|
endDate: u.endDate,
|
|
}))
|
|
|
|
// Adapter les filiations
|
|
const adaptedFiliations = filiations.map((f) => ({
|
|
id: f.id,
|
|
childId: f.childPersonId,
|
|
parentId: f.parentPersonId,
|
|
unionId: f.viaUnionId,
|
|
parentageType: f.parentageType || 'biologique',
|
|
displayOrder: f.displayOrder,
|
|
}))
|
|
|
|
// Adapter les médias
|
|
const adaptedMedias = medias.map((m) => ({
|
|
id: m.id,
|
|
personId: m.personId,
|
|
type: m.type,
|
|
url: m.type === 'photo' ? `/api${m.urlPath}` : null,
|
|
urlHd: m.type === 'photo' ? `/api${m.urlPath}` : null,
|
|
label: m.caption || t('Média {n}', { n: m.displayOrder }),
|
|
source: m.source || null,
|
|
displayOrder: m.displayOrder,
|
|
isFeatured: m.isFeatured,
|
|
}))
|
|
|
|
return {
|
|
persons: adaptedPersons,
|
|
unions: adaptedUnions,
|
|
filiations: adaptedFiliations,
|
|
medias: adaptedMedias,
|
|
}
|
|
}
|