feat(web): add emex + vin-api vehicle attribute extraction

Extend the source dispatcher to the remaining decode sources. emex surfaces its
parsedOptions codes (engine_type/gearbox_type/vehicle_type → Motor tipi /
Şanzıman tipi / Araç tipi), led by any readable DB columns (Vites, Kasa).
vin-api surfaces its flat fields (bodyClass, engineModel, transmissionStyle,
plantCountry → Kasa / Motor / Vites / Üretim ülkesi). Both replace the bare
3-field DB fallback these vehicles showed before.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-25 03:47:42 +03:00
parent 1549c14a09
commit 8fe731b7e0

View File

@@ -314,6 +314,38 @@ function fromPcat(vehicle: any): Attr[] {
.filter((a: Attr) => Boolean(a.label && a.value));
}
/** emex parsedOptions — bare codes; map the snake_case keys to Turkish. */
const EMEX_LABELS: Record<string, string> = {
engine_type: "Motor tipi",
gearbox_type: "Şanzıman tipi",
vehicle_type: "Araç tipi",
};
function fromEmex(vehicle: any): Attr[] {
const opts = vehicle?.rawData?.parsedOptions;
if (!opts || typeof opts !== "object") return [];
return Object.entries(EMEX_LABELS)
.map(([key, label]) => ({ label, value: String(opts[key] ?? "").trim() }))
.filter((a) => Boolean(a.value));
}
/** vin-api ships flat, human-readable fields. */
const VINAPI_FIELDS: Array<[string, string]> = [
["bodyClass", "Kasa"],
["engineModel", "Motor"],
["transmissionStyle", "Vites"],
["plantCountry", "Üretim ülkesi"],
];
function fromVinApi(vehicle: any): Attr[] {
const rd = vehicle?.rawData;
if (!rd) return [];
return VINAPI_FIELDS.map(([key, label]) => ({
label,
value: String(rd[key] ?? "").trim(),
})).filter((a) => Boolean(a.value));
}
/** Plain DB columns — last resort when no source payload is recognised. */
function getFallbackAttributes(vehicle: any): Attr[] {
return [
@@ -346,6 +378,22 @@ function getDisplayAttributes(vehicle: any): Attr[] {
if (a.length > 0) return a;
}
// emex — lead with any readable DB columns, then the option codes.
if (vehicle?.source === "emex") {
const dbExtras = [
{ label: "Vites", value: vehicle?.transmission },
{ label: "Kasa", value: vehicle?.bodyType },
].filter(isAttr);
const a = dropHeaderDupes([...dbExtras, ...fromEmex(vehicle)]);
if (a.length > 0) return a;
}
// vin-api — flat readable fields.
if (vehicle?.source === "vin-api") {
const a = dropHeaderDupes(fromVinApi(vehicle));
if (a.length > 0) return a;
}
return dropHeaderDupes(getFallbackAttributes(vehicle));
}