mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-18 16:52:11 +00:00
feat(personnes): saisir le sexe et nommer les liens de parenté en conséquence (#114)
- Champ Sexe (femme, homme, non précisé) dans la fiche en modification, à l'ajout d'une personne et dans une proposition de la famille ; relu « Sexe » dans les propositions à relire. - Valeurs ramenées à male / female / null à l'écriture et à la lecture (anciennes valeurs M/F relues sans migration), valeur inconnue refusée (400). Export GEDCOM inchangé dans sa forme. - Lien au survol genré quand le sexe est connu (Père, Tante, Cousine germaine, Belle-mère…), forme double sinon. Nommage déplacé dans utils/kinship : une fonction par langue reçoit le chemin complet (pas, personnes, sexe, année de naissance), pour brancher d'autres langues. - Anglais : beau-parent distingué de parent par alliance selon l'ordre du chemin (Stepmother / Mother-in-law). - Propositions à relire : le nom de la personne modifiée vient de l'avant lu en base quand la modification ne porte que le champ changé. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4dd0db9699
commit
eaecac8fa5
24 files changed
+521
-117
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
// Sexe d'une personne : 'male', 'female', ou null (non précisé). L'import GEDCOM écrit 'male'/'female',
|
||||
// d'anciens clients de l'API ont pu écrire 'M'/'F' : tout est ramené à ces deux valeurs, à l'écriture
|
||||
// comme à la lecture, sans migration des lignes existantes.
|
||||
export type PersonSex = 'male' | 'female'
|
||||
|
||||
const MALE = new Set(['male', 'm', 'homme', 'h'])
|
||||
const FEMALE = new Set(['female', 'f', 'femme'])
|
||||
const UNSPECIFIED = new Set(['', 'u', 'unknown', 'unspecified'])
|
||||
|
||||
// undefined : valeur que l'on ne sait pas lire (refusée à l'écriture)
|
||||
export function parseSex(value: string | null): PersonSex | null | undefined {
|
||||
if (value === null) return null
|
||||
const key = value.trim().toLowerCase()
|
||||
if (MALE.has(key)) return 'male'
|
||||
if (FEMALE.has(key)) return 'female'
|
||||
if (UNSPECIFIED.has(key)) return null
|
||||
return undefined
|
||||
}
|
||||
|
||||
// Lecture d'une valeur déjà en base : ce qu'on ne sait pas lire vaut « non précisé »
|
||||
export function sexOrNull(value: string | null | undefined): PersonSex | null {
|
||||
return parseSex(value ?? null) ?? null
|
||||
}
|
||||
|
||||
// Champ « sex » des schémas d'écriture : facultatif, null pour « non précisé », valeur ramenée à male/female
|
||||
export const sexSchema = z
|
||||
.string()
|
||||
.max(20)
|
||||
.nullable()
|
||||
.refine((value) => parseSex(value) !== undefined, { message: 'invalid_sex' })
|
||||
.transform((value) => parseSex(value) ?? null)
|
||||
.optional()
|
||||
@@ -14,6 +14,7 @@ import { findParentChildValidationError, findUnionValidationError } from '../uti
|
||||
import { nextSiblingOrder } from '../lib/sibling-order.js'
|
||||
import { personPrecisionResets, unionPrecisionResets } from '../lib/date-precision.js'
|
||||
import { hasAnyName } from '../lib/person-names.js'
|
||||
import { sexOrNull, sexSchema } from '../lib/person-sex.js'
|
||||
|
||||
const isoDateRegex = /^\d{4}-\d{2}-\d{2}$/
|
||||
|
||||
@@ -81,7 +82,7 @@ const personCreateSchema = z.object({
|
||||
profession: z.string().max(200).optional().nullable(),
|
||||
region: z.string().max(120).optional().nullable(),
|
||||
nationality: z.string().max(120).optional().nullable(),
|
||||
sex: z.string().max(20).optional().nullable(),
|
||||
sex: sexSchema,
|
||||
notes: z.string().max(2000).optional().nullable(),
|
||||
}).refine((value) => hasAnyName(value.firstName, value.lastName), { message: 'name_required', path: ['lastName'] })
|
||||
|
||||
@@ -99,7 +100,7 @@ const personUpdateSchema = z
|
||||
profession: z.string().max(200).optional().nullable(),
|
||||
region: z.string().max(120).optional().nullable(),
|
||||
nationality: z.string().max(120).optional().nullable(),
|
||||
sex: z.string().max(20).optional().nullable(),
|
||||
sex: sexSchema,
|
||||
notes: z.string().max(2000).optional().nullable(),
|
||||
})
|
||||
.refine((value) => Object.keys(value).length > 0, {
|
||||
@@ -869,6 +870,7 @@ async function snapshotEntity(
|
||||
...current,
|
||||
birthDate: current.birthDate?.toISOString().slice(0, 10) ?? null,
|
||||
deathDate: current.deathDate?.toISOString().slice(0, 10) ?? null,
|
||||
sex: sexOrNull(current.sex),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { indexGedcomRecords, mediaRefsForPerson, noteText, photoPathForPerson }
|
||||
import type { GedcomRecords } from '../lib/gedcom-photos.js'
|
||||
import type { MembershipRole } from '../types/auth.js'
|
||||
import { nextSiblingOrder } from '../lib/sibling-order.js'
|
||||
import { sexOrNull } from '../lib/person-sex.js'
|
||||
|
||||
const treeIdParamSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
@@ -455,8 +456,9 @@ export const gedcomRoutes: FastifyPluginAsync = async (app) => {
|
||||
lines.push(`1 NAME ${gedcomNameValue(person.firstName, person.lastName)}`)
|
||||
if (person.nickname) lines.push(`2 NICK ${oneLine(person.nickname)}`)
|
||||
|
||||
if (person.sex === 'male' || person.sex === 'M') lines.push('1 SEX M')
|
||||
else if (person.sex === 'female' || person.sex === 'F') lines.push('1 SEX F')
|
||||
const sex = sexOrNull(person.sex)
|
||||
if (sex === 'male') lines.push('1 SEX M')
|
||||
else if (sex === 'female') lines.push('1 SEX F')
|
||||
|
||||
const personEvents = eventsByPerson.get(person.id) ?? []
|
||||
const birthDetails = personEvents.find((event) => event.type === 'birth')
|
||||
@@ -518,9 +520,9 @@ export const gedcomRoutes: FastifyPluginAsync = async (app) => {
|
||||
const p1 = union.partner1PersonId ? personById.get(union.partner1PersonId) : null
|
||||
const p2 = union.partner2PersonId ? personById.get(union.partner2PersonId) : null
|
||||
|
||||
const p1IsFemale = p1?.sex === 'female' || p1?.sex === 'F'
|
||||
const p1IsMale = p1?.sex === 'male' || p1?.sex === 'M'
|
||||
const p2IsMale = p2?.sex === 'male' || p2?.sex === 'M'
|
||||
const p1IsFemale = sexOrNull(p1?.sex) === 'female'
|
||||
const p1IsMale = sexOrNull(p1?.sex) === 'male'
|
||||
const p2IsMale = sexOrNull(p2?.sex) === 'male'
|
||||
|
||||
// Swap to HUSB=male if we know p1 is female and p2 is male (or unknown)
|
||||
const shouldSwap = p1IsFemale && !p2IsMale === false ? false : p1IsFemale && (p2IsMale || !p1IsMale)
|
||||
@@ -675,7 +677,7 @@ export const gedcomRoutes: FastifyPluginAsync = async (app) => {
|
||||
: { firstName: '', lastName: '' }
|
||||
|
||||
const sexNode = findChild(indi, 'SEX')
|
||||
const sex = sexNode?.value === 'M' ? 'male' : sexNode?.value === 'F' ? 'female' : null
|
||||
const sex = sexOrNull(sexNode?.value)
|
||||
|
||||
const birtNode = findChild(indi, 'BIRT')
|
||||
const birthDateIso = gedcomDateToIso(findChild(birtNode, 'DATE')?.value ?? '')
|
||||
|
||||
@@ -17,6 +17,7 @@ import type { MembershipRole } from '../types/auth.js'
|
||||
import { findParentChildValidationError, findUnionValidationError } from '../utils/relationship-guards.js'
|
||||
import { personPrecisionResets, unionPrecisionResets } from '../lib/date-precision.js'
|
||||
import { hasAnyName } from '../lib/person-names.js'
|
||||
import { sexSchema } from '../lib/person-sex.js'
|
||||
import { ContributionRouteError, resolveSubmissionContext } from './contributions.js'
|
||||
|
||||
const MAX_TREES_PER_ACCOUNT = 10
|
||||
@@ -97,7 +98,7 @@ const createPersonSchema = z.object({
|
||||
profession: z.string().max(200).optional().nullable(),
|
||||
region: z.string().max(120).optional().nullable(),
|
||||
nationality: z.string().max(120).optional().nullable(),
|
||||
sex: z.string().max(20).optional().nullable(),
|
||||
sex: sexSchema,
|
||||
notes: z.string().max(2000).optional().nullable(),
|
||||
}).refine((value) => hasAnyName(value.firstName, value.lastName), { message: 'name_required', path: ['lastName'] })
|
||||
|
||||
@@ -115,7 +116,7 @@ const patchPersonSchema = z
|
||||
profession: z.string().max(200).optional().nullable(),
|
||||
region: z.string().max(120).optional().nullable(),
|
||||
nationality: z.string().max(120).optional().nullable(),
|
||||
sex: z.string().max(20).optional().nullable(),
|
||||
sex: sexSchema,
|
||||
notes: z.string().max(2000).optional().nullable(),
|
||||
})
|
||||
.refine((value) => Object.keys(value).length > 0, {
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Annotation, MediaItem, ParentChildLink, Person, Union } from '@pri
|
||||
import { sanitizeAnnotationContentForRead } from '../lib/annotation-content.js'
|
||||
import { readAvatarCrop, type AvatarCrop } from '../lib/avatar-crop.js'
|
||||
import { isImmichAvatarPath } from '../lib/media-files.js'
|
||||
import { sexOrNull } from '../lib/person-sex.js'
|
||||
|
||||
export type GraphPayload = {
|
||||
persons: Array<{
|
||||
@@ -98,7 +99,7 @@ export function buildGraphPayload(
|
||||
region: person.region,
|
||||
nationality: person.nationality,
|
||||
avatarUrlPath: person.avatarPath ? `/trees/${treeId}/persons/${person.id}/avatar` : null,
|
||||
sex: person.sex,
|
||||
sex: sexOrNull(person.sex),
|
||||
notes: person.notes,
|
||||
avatarFromImmich: isImmichAvatarPath(person.avatarPath),
|
||||
avatarCrop: person.avatarPath ? readAvatarCrop(person.avatarCrop) : null,
|
||||
|
||||
Reference in new issue
Block a user