48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
/** telefon z YAML (phone/cards.yaml -> cards[]) => { id, name, price_monthly, features[] } */
|
|
export function mapPhoneYamlToPlans(phoneCards) {
|
|
const list = Array.isArray(phoneCards) ? phoneCards : [];
|
|
return list
|
|
.filter((c) => c?.widoczny !== false)
|
|
.map((c, idx) => ({
|
|
id: String(c?.id ?? c?.nazwa ?? idx),
|
|
name: c?.nazwa ?? "—",
|
|
price_monthly: Number(c?.cena?.wartosc ?? 0),
|
|
features: (Array.isArray(c?.parametry) ? c.parametry : []).map((p) => ({
|
|
label: p.label,
|
|
value: p.value,
|
|
})),
|
|
}));
|
|
}
|
|
|
|
/** dekodery z YAML */
|
|
export function normalizeDecoders(list) {
|
|
const arr = Array.isArray(list) ? list : [];
|
|
return arr
|
|
.filter((d) => d?.id && d?.nazwa)
|
|
.map((d) => ({
|
|
id: String(d.id),
|
|
nazwa: String(d.nazwa),
|
|
opis: d.opis ? String(d.opis) : "",
|
|
cena: Number(d.cena ?? 0),
|
|
}));
|
|
}
|
|
|
|
/** dodatki z YAML (tv-addons.yaml / addons.yaml) */
|
|
export function normalizeAddons(addons) {
|
|
const list = Array.isArray(addons) ? addons : [];
|
|
return list
|
|
.filter((a) => a?.id && a?.nazwa)
|
|
.map((a) => ({
|
|
id: String(a.id),
|
|
nazwa: String(a.nazwa),
|
|
typ: String(a.typ ?? a.type ?? "checkbox"),
|
|
ilosc: !!a.ilosc,
|
|
min: a.min != null ? Number(a.min) : 0,
|
|
max: a.max != null ? Number(a.max) : 10,
|
|
krok: a.krok != null ? Number(a.krok) : 1,
|
|
opis: a.opis ? String(a.opis) : "",
|
|
cena: a.cena ?? 0,
|
|
tid: a.tid != null ? String(a.tid) : "",
|
|
}));
|
|
}
|