Add request single page

This commit is contained in:
2026-01-01 11:52:24 +01:00
parent 42f23dddcf
commit 2fcf19c0df
13 changed files with 1007 additions and 83 deletions

View File

@ -0,0 +1,48 @@
export type PriceSource = {
price?: number | null;
pricePercent?: number | null;
priceRange?: string | null;
};
export function calculatePrice(source: PriceSource, base: number): number {
if (source.price != null) return source.price;
if (source.pricePercent != null) return base * (source.pricePercent / 100);
if (source.priceRange) {
const parts = source.priceRange.split("").map(Number);
const max = Math.max(...parts);
return Number.isNaN(max) ? 0 : max;
}
return 0;
}
export function calculatePriceRange(
baseSource: PriceSource | undefined,
extras: PriceSource[]
): [number, number] {
if (!baseSource) return [0, 0];
const base = calculatePrice(baseSource, 0);
let minExtra = 0;
let maxExtra = 0;
for (const extra of extras) {
if (extra.price != null) {
minExtra += extra.price;
maxExtra += extra.price;
} else if (extra.pricePercent != null) {
const val = base * (extra.pricePercent / 100);
minExtra += val;
maxExtra += val;
} else if (extra.priceRange) {
const [minStr, maxStr] = extra.priceRange.split("");
const min = Number(minStr);
const max = Number(maxStr);
if (!Number.isNaN(min)) minExtra += min;
if (!Number.isNaN(max)) maxExtra += max;
}
}
return [base + minExtra, base + maxExtra];
}