// ... | |
@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