Closed Migushthe2nd closed 2 years ago
@Migushthe2nd Sorry for the late reply.
With the current implementation of this library and pipes handling (ValidationPipe
handles class-validator
) in Nest.js it seems impossible to me to implement this feature.
The problem is that pipes are executed separately and before the controller code is executed:
Roughly it looks like this:
() => {
const pipes = executePipes();
const response = entityController.updateEntity();
}
With @Transactional()
decorator for controller method it looks like:
() => {
const pipes = executePipes();
await runInTransaction(async () =>
const response = entityController.updateEntity();
}
}
To work with pipes in same transactional context we need to wrap code that execute both pipes and controller code inside runInTransaction
.
We need something like that:
() => {
await runInTransaction(async () =>
const pipes = executePipes();
const response = entityController.updateEntity();
}
}
But so far I don't see any solution other than manually handling ValidationPipe
inside controller method. It seems Nest.js doesn't offer anything to handle it.
I use this module in combination with NestJS. I have implemented custom validators to validate e.g. parameters (
@Params
) in a request supplied by the user. This in order to check whether entities exist before continuing running the body of a controller method. The issue I have is that this interaction by the user is executed in two transactions: one is started and committed by the class validator, the other is started and committed after this class validator upon running the service method (Controller -> Service -> update). This could result in a situation:Would it somehow be possible to have the validator and service share the same transaction?
The structure is as follows.
Class Validator
entity-exists.validator.ts
Params
get-entity-by-id.params.ts
Controller
entity.controller.ts
Service
entity.service.ts
What I have considered
Service.update()
, but that would make the class validator obsolete. I use the validators because class-validators generate a specific error response format.Thank you for updating the module for the latest TypeORM version by the way!