From becfdf2fe4b4d631a85c5034266c271ed61af0b1 Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 5 Jan 2024 22:32:35 +0100 Subject: [PATCH] Hotfix stripe transaction bug (#132) * 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. --- src/service/stripe-service.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/service/stripe-service.ts b/src/service/stripe-service.ts index 40f4653b4..513b72059 100644 --- a/src/service/stripe-service.ts +++ b/src/service/stripe-service.ts @@ -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 { return StripeDeposit.findOne({ where: { id }, relations: ['depositStatus'].concat(relations), @@ -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(),