Skip to content

Commit

Permalink
Hotfix for stripe transaction erroring on deposit update (#131)
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
  • Loading branch information
JustSamuel authored Jan 5, 2024
1 parent f707d01 commit 07454ed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/service/stripe-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import {
StripePaymentIntentResponse,
} from '../controller/response/stripe-response';
import TransferService from './transfer-service';
import {EntityManager, IsNull} from 'typeorm';
import { EntityManager, IsNull } from 'typeorm';
import { parseUserToBaseResponse } from '../helpers/revision-to-response';
import wrapInManager from "../helpers/database";
import wrapInManager from '../helpers/database';

export const STRIPE_API_VERSION = '2022-08-01';

Expand Down Expand Up @@ -158,7 +158,7 @@ export default class StripeService {
throw new Error('Cannot create status FAILED, because SUCCEEDED already exists');
}

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

// If payment has succeeded, create the transfer
Expand All @@ -173,7 +173,7 @@ export default class StripeService {
toId: deposit.to.id,
description: deposit.stripeId,
fromId: undefined,
});
}, manager);

await manager.save(deposit);
}
Expand Down
2 changes: 1 addition & 1 deletion src/subscriber/transfer-subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class TransferSubscriber implements EntitySubscriberInterface {
// Remove currently unpaid fines when new balance is positive.
if (currentBalance >= 0) {
user.currentFines = null;
await user.save();
await event.manager.save(user);
}
}
}
2 changes: 0 additions & 2 deletions test/unit/controller/transaction-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import { TransactionRequest } from '../../../src/controller/request/transaction-
import { defaultPagination, PAGINATION_DEFAULT, PaginationResult } from '../../../src/helpers/pagination';
import { inUserContext, UserFactory } from '../../helpers/user-factory';
import MemberAuthenticator from '../../../src/entity/authenticator/member-authenticator';
import { tr } from 'date-fns/locale';
import { validDate } from '../../../src/controller/request/validators/duration-spec';

describe('TransactionController', (): void => {
let ctx: {
Expand Down

0 comments on commit 07454ed

Please sign in to comment.