Open icodefish opened 2 years ago
Hi,
I agree with you, if we take the BookServices, in the createBook() method the ORM generates a Book from the file "frameworks/data-services/mongo/model/book.model.ts" (of type BookDocument). On the other hand, the createBook() method returns a Book from the file "core/entities/book.entity.ts" which is not at all related to the Mongoose entity.
How to solve this problem ?
Should we have an abstract method in the
"frameworks/data-services/mongo/model/book.model.ts" class which allows to generate a book based on a mongoose book entity?
Hey,
TypeScript is checking for computability between src/frameworks/data-services/mongo/model/book.model.ts
and src/core/entities/book.entity.ts
if you try to change or omit one of the properties in the model, typescript will give an error.
for example I have omitted publishDate
from the model and gut an error:
other approach is to use a different ORM like typeorm
and use generic annotations in your entities - https://docs.nestjs.com/techniques/database
it is still not clean as you would want it to be but it is a good compromise, you are coupling to an ORM and not for a DB.
I prefer to stay with the approach I have implemented
Hi,
great article but here's the problem I came across while looking through your code. In your
MongoDataServices
class you import yourAuthor
,Book
andGenre
from your mongo models but the abstract class IDataServices makes use ofAuthor
,Book
andGenre
that come from entites of the core directory. And these classes are different so my linter cries with errors.