Skip to content

Commit

Permalink
Hotfix stripe transaction bug (#132)
Browse files Browse the repository at this point in the history
* Fixed bug where typeorm would error on trying to save the deposit status in the transaction.

* lint-fix

* The bug was that when in a transaction if you save an object only the response from .then on the save function will have an idea. So you have to use that instead of assuming that every saved object "gets" an id.
  • Loading branch information
JustSamuel authored Jan 5, 2024
1 parent 07454ed commit becfdf2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/service/stripe-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class StripeService {
.map((d) => this.asStripeDepositResponse(d));
}

public static async getStripeDeposit(id: number, relations: string[] = []) {
public static async getStripeDeposit(id: number, relations: string[] = []): Promise<StripeDeposit> {
return StripeDeposit.findOne({
where: { id },
relations: ['depositStatus'].concat(relations),
Expand Down Expand Up @@ -158,12 +158,13 @@ export default class StripeService {
throw new Error('Cannot create status FAILED, because SUCCEEDED already exists');
}

const depositStatus = Object.assign(new StripeDepositStatus(), { deposit: { id: deposit.id }, state });
await manager.save(depositStatus);
const depositStatus = Object.assign(new StripeDepositStatus(), { deposit, state });
await manager.save(depositStatus).then((depositState) => {
deposit.depositStatus.push(depositState);
});

// If payment has succeeded, create the transfer
if (state === StripeDepositState.SUCCEEDED) {
deposit = await StripeService.getStripeDeposit(depositId, ['to']);
deposit.transfer = await TransferService.createTransfer({
amount: {
amount: deposit.amount.getAmount(),
Expand Down

0 comments on commit becfdf2

Please sign in to comment.