Last active
February 11, 2021 18:37
-
-
Save alphamikle/a393c7a748ec60d873f3a33af5a23098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
@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