TypeError: dto.toEntity is not a function
fernandodeabreupereira opened this issue · 2 comments
Hello, first I would like to thank you for the beautiful example presented by you.
I'm trying to replicate your code, following the article posting on Medium (https://medium.com/@gausmann.simon/nestjs-typeorm-and-postgresql-full-example-development-and-project-setup-working- with-database-c1a2b1b11b8f). I reached the end, but when I POST to / item, I get the following message:
Can you help me? Thank you!
Hello, thank you for your excellent article :)
I have the same problem and this is my solution :
Inside item.dto.ts make the method toEntity static :
public static toEntity(dto: ItemDTO, user: User = null) { ... }
and inside item.service.ts :
return this.repo.create(ItemDTO.toEntity(dto, user))
best reguards
Thanks @fcastell for pointing that out.
fixed the demo code here
4a9bc8c969915898bbc888a4348129a4a0486a8f