@@ -190,6 +190,7 @@ interface Props {
190190 amount: number ;
191191}
192192
193+ // simple example as monetary value object business behavior
193194export default class Money extends ValueObject <Props > {
194195
195196 // private constructor. Avoid public new.
@@ -295,36 +296,24 @@ interface Props {
295296 fees: Money ;
296297}
297298
298- // simple example as monetary value object business behavior
299+ // simple example as payment entity using money value object
299300export default class Payment extends Entity <Props > {
300301
301302 // private constructor
302303 private constructor (props : Props ){
303304 super (props );
304305 }
305306
306- // any business rule behavior. Discount must be less or equal total.
307- public checkDiscount(value : Money ): Money {
308- const total = this .props .total ;
309- const isGt = value .isGt (total );
310- if (isGt ) return total ;
311- return value ;
312- }
313-
314307 // any business rule behavior. Update total.
315- public applyFees(value : Money ): Payment {
308+ public applyFees(fees : Money ): Payment {
316309 const props = this .props ;
317- const currentFee = this .props .fee ;
318- const fees = currentFee .sum (value );
319310 const total = props .total .sum (fees );
320311 return new Payment ({ ... props , total , fees });
321312 }
322313
323314 // any business rule behavior. Discount must be less or equal total.
324- public applyDiscount(value : Money ): Payment {
315+ public applyDiscount(discount : Money ): Payment {
325316 const props = this .props ;
326- const result = this .checkDiscount (value );
327- const discount = props .discount .subtract (result );
328317 const total = props .total .subtract (discount );
329318 return new Payment ({ ... props , total , discount });
330319 }
@@ -376,4 +365,4 @@ console.log(result.toObject());
376365
377366## Lib Full Documentation
378367
379- Check lib documentation on link [ Here] ( https://github.com/4lessandrodev/types-ddd/tree/main/docs )
368+ Check lib documentation on link [ Here] ( https://github.com/4lessandrodev/types-ddd/tree/main/docs )
0 commit comments