Open JustSamuel opened 3 months ago
Looks nice, but we need to watch out that this might not work everywhere. In many places, we use Object.assign()
to create new entities, but these entities do not necessarily have all entity attributes, especially methods will be missing.
Regarding the base
parameter, I think it is much better to just define two separate methods, as that deals correctly with return types. Then the asBaseResponse()
method returns a BaseResponse
and the asResponse()
method returns a Response
type.
Looks nice, but we need to watch out that this might not work everywhere. In many places, we use
Object.assign()
to create new entities, but these entities do not necessarily have all entity attributes, especially methods will be missing.
Should be fine? We usually save them in the meantime. I don't think there will be a lot of issues, but we could always check.
Regarding the
base
parameter, I think it is much better to just define two separate methods, as that deals correctly with return types. Then theasBaseResponse()
method returns aBaseResponse
and theasResponse()
method returns aResponse
type.
Agree
We currently have a lot of service classes with a function along the lines of
revisionToResponse
, take for example thebanner-service.ts
However I think it might be nicer to move this code to the entity? This also forces the idea that service deal with entities, not responses, and moves that in a more clearer fashion to the controller.
This is the current
banner.ts
How about we add a .toResponse function? I suggest we add a param
base
which indicates if it needs any of its relations loaded, in the case of abase
it will only return a response with its own properties. This is also way clearer to the programmer what a base response should be.Using the entity based approach we can also make use of the extensions from the base entity, by calling .super for
.toResponse
See this commit / branch as en example: https://github.com/GEWIS/sudosos-backend/commit/f7b31b520cf0d4e383df37946ca746b2674159c4