From 02db6f030cc7c35a6fc07ceec4ad54c35a0fd244 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Fri, 23 Feb 2024 17:12:41 +0100 Subject: [PATCH] fix tx in tz --- src/services/main/paymentManager.ts | 4 ++-- src/services/storage/paymentStorage.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index b5e0994a..38f9474d 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -485,9 +485,9 @@ export default class { const toIncrement = amount - fee await this.storage.userStorage.DecrementUserBalance(fromUser.user_id, amount, tx) await this.storage.userStorage.IncrementUserBalance(toUser.user_id, toIncrement, tx) - await this.storage.paymentStorage.AddUserToUserPayment(fromUserId, toUserId, amount, fee, linkedApplication) + await this.storage.paymentStorage.AddUserToUserPayment(fromUserId, toUserId, amount, fee, linkedApplication, tx) if (isAppUserPayment && fee > 0) { - await this.storage.userStorage.IncrementUserBalance(linkedApplication.owner.user_id, fee) + await this.storage.userStorage.IncrementUserBalance(linkedApplication.owner.user_id, fee, tx) } sentAmount = toIncrement }) diff --git a/src/services/storage/paymentStorage.ts b/src/services/storage/paymentStorage.ts index c8af90e9..999704fc 100644 --- a/src/services/storage/paymentStorage.ts +++ b/src/services/storage/paymentStorage.ts @@ -228,8 +228,8 @@ export default class { return found } - async AddUserToUserPayment(fromUserId: string, toUserId: string, amount: number, fee: number, linkedApplication: Application) { - const newKey = this.DB.getRepository(UserToUserPayment).create({ + async AddUserToUserPayment(fromUserId: string, toUserId: string, amount: number, fee: number, linkedApplication: Application, dbTx: DataSource | EntityManager) { + const newKey = dbTx.getRepository(UserToUserPayment).create({ from_user: await this.userStorage.GetUser(fromUserId), to_user: await this.userStorage.GetUser(toUserId), paid_at_unix: Math.floor(Date.now() / 1000), @@ -237,7 +237,7 @@ export default class { service_fees: fee, linkedApplication }) - return this.txQueue.PushToQueue({ exec: async db => db.getRepository(UserToUserPayment).save(newKey), dbTx: false }) + return dbTx.getRepository(UserToUserPayment).save(newKey) } GetUserToUserReceivedPayments(userId: string, fromIndex: number, take = 50, entityManager = this.DB) {