Presupuestador_web/shared/lib/contexts/common/domain/entities/UnitPrice.ts

28 lines
690 B
TypeScript
Raw Normal View History

2024-07-09 16:21:21 +00:00
import { NullOr } from "../../../../utilities";
import { MoneyValue } from "./MoneyValue";
import { Result } from "./Result";
2024-04-23 15:29:38 +00:00
export interface IUnitPriceProps {
amount: NullOr<number | string>;
currencyCode?: string;
2024-07-15 15:41:42 +00:00
scale: number;
2024-04-23 15:29:38 +00:00
}
export class UnitPrice extends MoneyValue {
public static create(props: IUnitPriceProps) {
2024-07-15 15:41:42 +00:00
const { amount, currencyCode, scale = 4 } = props;
2024-04-23 15:29:38 +00:00
const _unitPriceOrError = MoneyValue.create({
amount,
currencyCode,
2024-07-15 15:41:42 +00:00
scale,
2024-04-23 15:29:38 +00:00
});
if (_unitPriceOrError.isFailure) {
return _unitPriceOrError;
}
2024-07-15 15:41:42 +00:00
const _unitPrice = _unitPriceOrError.object.convertScale(4);
2024-04-23 15:29:38 +00:00
return Result.ok<UnitPrice>(_unitPrice);
}
}