Skip to content

Instantly share code, notes, and snippets.

@alphamikle
Last active February 11, 2021 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphamikle/a393c7a748ec60d873f3a33af5a23098 to your computer and use it in GitHub Desktop.
Save alphamikle/a393c7a748ec60d873f3a33af5a23098 to your computer and use it in GitHub Desktop.
// ...
@Post('remittance-with-transaction-and-fee')
@ApiResponse({
type: RemittanceResultDto,
})
async makeRemittanceWithTransactionAndFee(@Body() remittanceDto: RemittanceDto) {
return this.connection.transaction(async manager => {
const transactionAppService = this.appService.withTransaction(manager); // <-- this is interesting new thing
const result = await transactionAppService.makeRemittance(remittanceDto.userIdFrom, remittanceDto.userIdTo, remittanceDto.sum, remittanceDto.withError);
result.fromBalance -= 1; // <-- transfer fee
const senderPurse = await transactionAppService.getPurse(remittanceDto.userIdFrom);
senderPurse.balance -= 1; // <-- transfer fee, for example of using several services in one transaction in controller
await this.appServiceV2.withTransaction(manager).savePurse(senderPurse);
return result;
});
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment