From 12ffca93eb7c1eb68c520737b7c5e9af987195ee Mon Sep 17 00:00:00 2001 From: 4lessandrodev Date: Thu, 28 Nov 2024 01:35:36 -0300 Subject: [PATCH] docs: update readme --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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); + } } ```