diff --git a/README.md b/README.md index 49c10a7..94d5966 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,15 @@ export default class Money extends ValueObject { return Ok(new Money({ amount })); } + + // try initialize an instance. throw erro if provide an invalid value + public static init(amount: number): Money { + + const isValid = this.isValidProps({ amount }); + if(!isValid) throw new Error("Invalid amount for money"); + + return new Money({ amount }); + } } ``` @@ -377,6 +386,10 @@ export default class Payment extends Entity { public static create(props: Props): Result { return Ok(new Payment(props)); } + + public static init(props: Props): Payment { + return new Payment(props); + } } ``` @@ -513,6 +526,10 @@ export default class Order extends Aggregate { public static create(props: Props): Result { return Ok(new Order(props)); } + + public static init(props: Props): Order { + return new Order(props); + } } ```