- API PATCH …/fiche, POST/DELETE …/enfants/:enfantId, GET avec amChildren - Table enfants_assistantes_maternelles (option D, 1 garde active/enfant) - Statuts enfant: garde/sans_garde remplacent actif (inscription → sans_garde) - BDD.sql canonique réécrit; migration pour BDD existantes - Seed test: hash bcrypt corrigé pour mot de passe « password » Co-authored-by: Cursor <cursoragent@cursor.com>
29 lines
962 B
TypeScript
29 lines
962 B
TypeScript
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
|
import { AmChildren } from 'src/entities/am_children.entity';
|
|
import { sanitizeUserForApi } from '../../common/utils/sanitize-user-for-api';
|
|
|
|
/**
|
|
* Sérialisation API fiche AM — ticket #131.
|
|
* Expose `amChildren` actifs (date_fin null) avec enfant imbriqué, sans secrets user.
|
|
*/
|
|
export function mapAmForApi(am: AssistanteMaternelle): AssistanteMaternelle {
|
|
const activeChildren = (am.amChildren ?? []).filter((link) => !link.date_fin);
|
|
|
|
return {
|
|
...am,
|
|
user: sanitizeUserForApi(am.user)!,
|
|
amChildren: activeChildren.map((link) => ({
|
|
...link,
|
|
child: link.child,
|
|
})),
|
|
};
|
|
}
|
|
|
|
export function mapAmsForApi(ams: AssistanteMaternelle[]): AssistanteMaternelle[] {
|
|
return ams.map(mapAmForApi);
|
|
}
|
|
|
|
export function filterActiveAmChildren(links: AmChildren[] | undefined): AmChildren[] {
|
|
return (links ?? []).filter((link) => !link.date_fin);
|
|
}
|