4lessandrodev / rich-domain

A lib to help you create a robust project based on domain driven-design (ddd) principles with typescript and zero dependencies.
https://www.npmjs.com/package/rich-domain
MIT License
122 stars 5 forks source link

fix(auto-mapper): fix processing simple object #26

Closed 4lessandrodev closed 1 year ago

4lessandrodev commented 1 year ago

Describe the bug toObject method on entity is not processing simple objects

To Reproduce


interface Profile {
  name: string;
  age: number;
}

interface Props {
  id?: UID;
  profile: Profile;
}

class Example extends Entity<Props>{}

const example = Example.create({ profile: { name: "Jane", age:21 } }).value();

console.log(example.toObject()):

> {  
       id: "4666ce4b-10d9-4999-9da8-0caef5b7fd50", 
       createdAt: "2023-01-05T18:34:54.198Z", 
       updatedAt: "2023-01-05T18:34:54.198Z" 
 };

Expected behavior the toObject method should process simple object and apply it to generated props

console.log(example.toObject()):

> {  
       id: "4666ce4b-10d9-4999-9da8-0caef5b7fd50", 
       createdAt: "2023-01-05T18:34:54.198Z", 
       updatedAt: "2023-01-05T18:34:54.198Z",
       profile: { name: "Jane", age: 21 }
 };

Lib Version rich-domain v1.15.1

25