This commit is contained in:
Matthieu
2026-03-31 17:53:30 +02:00
parent e0f761da2b
commit 958a00c8fc
21 changed files with 281 additions and 144 deletions

View File

@@ -139,49 +139,3 @@ export const formatConstructeurContact = (
return [constructeur.email, phone].filter(Boolean).join(' • ');
};
export const buildConstructeurRequestPayload = <T extends Record<string, any>>(
payload: T,
): T & { constructeurs?: string[] } => {
const collected = new Set(uniqueConstructeurIds(
payload?.constructeurIds,
payload?.constructeurId,
payload?.constructeur,
payload?.constructeurs,
));
if (!collected.size) {
const fallbackLists = [
payload?.constructeurIds,
payload?.constructeurs,
];
fallbackLists.forEach((list) => {
if (!Array.isArray(list)) {
return;
}
list.forEach((item) => {
if (typeof item === 'string') {
const id = toStringId(item);
if (id) {
collected.add(id);
}
return;
}
if (isObject(item) && typeof item.id === 'string') {
collected.add(item.id);
}
});
});
}
const ids = Array.from(collected);
const next = { ...payload } as Record<string, any>;
delete next.constructeurId;
delete next.constructeur;
delete next.constructeurs;
delete next.constructeurIds;
next.constructeurs = ids.map((id) => `/api/constructeurs/${id}`);
return next as T & { constructeurs?: string[] };
};