1
0
forked from Yara724/api

Fixed bugs

This commit is contained in:
SepehrYahyaee
2026-05-12 11:07:58 +03:30
parent f75e6a4453
commit e26c533a52
2 changed files with 72 additions and 1 deletions

View File

@@ -298,6 +298,40 @@ export function partIdentityKey(p: DamageSelectedPartV2): string {
return `${p.side}|${p.name}`;
}
/**
* Same canonical identity as `partIdentityKey`, but derived directly from a
* unified `carPartDamage` snapshot (the shape we persist on
* `evaluation.damageExpertReply*.parts[].carPartDamage`).
*
* Returns `null` when the input cannot produce an identity (no `id`, no
* `name`). Callers should treat that as an invalid expert reply line.
*/
export function partIdentityKeyFromCarPartDamage(
carPartDamage: unknown,
): string | null {
if (
!carPartDamage ||
typeof carPartDamage !== "object" ||
Array.isArray(carPartDamage)
) {
return null;
}
const o = carPartDamage as Record<string, unknown>;
const idRaw = o.id;
const id =
typeof idRaw === "number" && Number.isFinite(idRaw)
? idRaw
: typeof idRaw === "string" &&
idRaw.trim() &&
Number.isFinite(Number(idRaw))
? Number(idRaw)
: null;
const name = typeof o.name === "string" ? o.name.trim() : "";
const side = typeof o.side === "string" ? o.side.trim() : "";
if (id == null && !name) return null;
return partIdentityKey({ id, name, side, label_fa: "" });
}
function normPartSegment(s: string): string {
return String(s ?? "").replace(/[^a-z0-9]/gi, "").toLowerCase();
}