feat(front): aligner api platform et sessions [INV-20260111-02]
This commit is contained in:
@@ -15,7 +15,14 @@ const toStringId = (value: unknown): string | null => {
|
||||
return null;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
if (trimmed.includes('/')) {
|
||||
const parts = trimmed.split('/').filter(Boolean);
|
||||
return parts.length ? parts[parts.length - 1] : null;
|
||||
}
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
export const uniqueConstructeurIds = (...sources: unknown[]): string[] => {
|
||||
@@ -107,7 +114,7 @@ export const formatConstructeurContact = (
|
||||
|
||||
export const buildConstructeurRequestPayload = <T extends Record<string, any>>(
|
||||
payload: T,
|
||||
): T & { constructeurIds: string[] } => {
|
||||
): T & { constructeurs?: string[] } => {
|
||||
const ids = uniqueConstructeurIds(
|
||||
payload?.constructeurIds,
|
||||
payload?.constructeurId,
|
||||
@@ -116,10 +123,13 @@ export const buildConstructeurRequestPayload = <T extends Record<string, any>>(
|
||||
);
|
||||
|
||||
const next = { ...payload } as Record<string, any>;
|
||||
next.constructeurIds = ids;
|
||||
if (ids.length) {
|
||||
next.constructeurs = ids.map((id) => `/api/constructeurs/${id}`);
|
||||
}
|
||||
delete next.constructeurId;
|
||||
delete next.constructeur;
|
||||
delete next.constructeurs;
|
||||
delete next.constructeurIds;
|
||||
|
||||
return next as T & { constructeurIds: string[] };
|
||||
return next as T & { constructeurs?: string[] };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user