royib / clean-architecture-nestJS

An in-depth implementation of Clean Architecture using NestJS and type-script
795 stars 192 forks source link

How to get Ids of entities #12

Open Pipo93 opened 1 year ago

Pipo93 commented 1 year ago

I have a question regarding entities. I can't see anything regarding Ids in the entities and the create as well as the get endpoints are returning elements of those entities. How can the clients then know which id they need to send to update/ delete for example an author or book? I assume something is missing and it just works because although typescript does not know about the ids Mongoose returns them with the responses.

jemsgit commented 11 months ago

Hi! Have the same question. I think we can't find anything in our repository by Id because client can't get Id from our models.

alande-amorim commented 5 months ago

@Pipo93 is you domain entity really expected to have an id property? Is it part of your Critical Business Rules? Or is the id a database commodity? Does it make part of your domain entity or to your database model?

"An Entity is an object within our computer system that embodies a small set of critical business rules operating on Critical Business Data. The Entity object either contains the Critical Business Data or has very easy access to that data. The interface of the Entity consists of the functions that implement the Critical Business Rules that operate on that data."(Martin, Robert C. Clean Architecture. Boston: Prentice Hall, 2017, 186.)

also

"... many database frameworks return a convenient data format in response to a query. We might call this a “row structure.” We don’t want to pass that row structure inward across a boundary. Doing so would violate the Dependency Rule because it would force an inner circle to know something about an outer circle." (p. 200)