fix(tickets): normalise createdBy manquant sur les payloads legacy
Les tickets legacy sans champ createdBy faisaient noircir la fenêtre tickets côté frontend. Les adapters (ticket.ts, streamGateways.ts) normalisent désormais ce champ absent, avec couverture de test dédiée. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -42,6 +42,18 @@ export function isTicketVersionConflict(error: unknown): boolean {
|
||||
return typeof message === "string" && message.includes("version conflict");
|
||||
}
|
||||
|
||||
const LEGACY_TICKET_ACTOR: Ticket["createdBy"] = { kind: "user" };
|
||||
|
||||
function normalizeTicketActor(actor: unknown): Ticket["createdBy"] {
|
||||
if (!actor || typeof actor !== "object") return LEGACY_TICKET_ACTOR;
|
||||
const rec = actor as Record<string, unknown>;
|
||||
if (rec.kind === "user" || rec.kind === "system") return { kind: rec.kind };
|
||||
if (rec.kind === "agent" && typeof rec.agentId === "string" && rec.agentId) {
|
||||
return { kind: "agent", agentId: rec.agentId };
|
||||
}
|
||||
return LEGACY_TICKET_ACTOR;
|
||||
}
|
||||
|
||||
function normalizeTicket(ticket: Ticket): Ticket {
|
||||
return {
|
||||
...ticket,
|
||||
@ -50,6 +62,8 @@ function normalizeTicket(ticket: Ticket): Ticket {
|
||||
? ticket.assignedAgentIds
|
||||
: [],
|
||||
attachments: Array.isArray(ticket.attachments) ? ticket.attachments : [],
|
||||
createdBy: normalizeTicketActor(ticket.createdBy),
|
||||
updatedBy: normalizeTicketActor(ticket.updatedBy),
|
||||
};
|
||||
}
|
||||
|
||||
@ -62,6 +76,7 @@ function normalizeTicketList(list: TicketList): TicketList {
|
||||
assignedAgentIds: Array.isArray(item.assignedAgentIds)
|
||||
? item.assignedAgentIds
|
||||
: [],
|
||||
createdBy: normalizeTicketActor(item.createdBy),
|
||||
}))
|
||||
: [],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user