feat: resolve unit price from catalog with selection override
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
18
mvp/b2c/src/budget/resolve.ts
Normal file
18
mvp/b2c/src/budget/resolve.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { Calidad, CategoriaMaterial, CatalogItem } from './types';
|
||||
|
||||
export function resolvePrecioUnitario(
|
||||
categoria: CategoriaMaterial,
|
||||
calidad: Calidad,
|
||||
catalog: CatalogItem[],
|
||||
selections: Partial<Record<CategoriaMaterial, string>>,
|
||||
): { item: CatalogItem | null } {
|
||||
const selectedId = selections[categoria];
|
||||
if (selectedId) {
|
||||
const selected = catalog.find((c) => c.id === selectedId);
|
||||
if (selected) return { item: selected };
|
||||
}
|
||||
const def = catalog.find(
|
||||
(c) => c.categoria === categoria && c.calidad === calidad && c.esDefault,
|
||||
);
|
||||
return { item: def ?? null };
|
||||
}
|
||||
Reference in New Issue
Block a user