28 lines
690 B
TypeScript
28 lines
690 B
TypeScript
import { NullOr } from "../../../../utilities";
|
|
import { MoneyValue } from "./MoneyValue";
|
|
import { Result } from "./Result";
|
|
|
|
export interface IUnitPriceProps {
|
|
amount: NullOr<number | string>;
|
|
currencyCode?: string;
|
|
scale: number;
|
|
}
|
|
|
|
export class UnitPrice extends MoneyValue {
|
|
public static create(props: IUnitPriceProps) {
|
|
const { amount, currencyCode, scale = 4 } = props;
|
|
const _unitPriceOrError = MoneyValue.create({
|
|
amount,
|
|
currencyCode,
|
|
scale,
|
|
});
|
|
if (_unitPriceOrError.isFailure) {
|
|
return _unitPriceOrError;
|
|
}
|
|
|
|
const _unitPrice = _unitPriceOrError.object.convertScale(4);
|
|
|
|
return Result.ok<UnitPrice>(_unitPrice);
|
|
}
|
|
}
|