diff --git a/src/services/main/appUserManager.ts b/src/services/main/appUserManager.ts index b87a648d..b9bf8742 100644 --- a/src/services/main/appUserManager.ts +++ b/src/services/main/appUserManager.ts @@ -192,6 +192,10 @@ export default class { await this.storage.paymentStorage.RemoveUserInvoices(userId, tx) await this.storage.productStorage.RemoveUserProducts(userId, tx) await this.storage.paymentStorage.RemoveUserEphemeralKeys(userId, tx) + await this.storage.paymentStorage.RemoveUserInvoicePayments(userId, tx) + await this.storage.paymentStorage.RemoveUserTransactionPayments(userId, tx) + await this.storage.paymentStorage.RemoveUserToUserPayments(userId, tx) + await this.storage.paymentStorage.RemoveUserReceivingAddresses(userId, tx) await this.storage.userStorage.DeleteUserAccess(userId, tx) await this.storage.applicationStorage.RemoveAppUsersAndBaseUsers(appUserIds, userId, tx) }) diff --git a/src/services/storage/paymentStorage.ts b/src/services/storage/paymentStorage.ts index 092ef8df..af96b6c5 100644 --- a/src/services/storage/paymentStorage.ts +++ b/src/services/storage/paymentStorage.ts @@ -341,6 +341,42 @@ export default class { return deleted } + async RemoveUserReceivingAddresses(userId: string, txId?: string) { + const addresses = await this.dbs.Find('UserReceivingAddress', { where: { user: { user_id: userId } } }, txId) + for (const addr of addresses) { + const txs = await this.dbs.Find('AddressReceivingTransaction', { where: { user_address: { serial_id: addr.serial_id } } }, txId) + for (const tx of txs) { + await this.dbs.Delete('AddressReceivingTransaction', tx.serial_id, txId) + } + await this.dbs.Delete('UserReceivingAddress', addr.serial_id, txId) + } + } + + async RemoveUserInvoicePayments(userId: string, txId?: string) { + const payments = await this.dbs.Find('UserInvoicePayment', { where: { user: { user_id: userId } } }, txId) + for (const p of payments) { + await this.dbs.Delete('UserInvoicePayment', p.serial_id, txId) + } + } + + async RemoveUserTransactionPayments(userId: string, txId?: string) { + const payments = await this.dbs.Find('UserTransactionPayment', { where: { user: { user_id: userId } } }, txId) + for (const p of payments) { + await this.dbs.Delete('UserTransactionPayment', p.serial_id, txId) + } + } + + async RemoveUserToUserPayments(userId: string, txId?: string) { + const asSender = await this.dbs.Find('UserToUserPayment', { where: { from_user: { user_id: userId } } }, txId) + const asReceiver = await this.dbs.Find('UserToUserPayment', { where: { to_user: { user_id: userId } } }, txId) + const seen = new Set() + for (const p of [...asSender, ...asReceiver]) { + if (seen.has(p.serial_id)) continue + seen.add(p.serial_id) + await this.dbs.Delete('UserToUserPayment', p.serial_id, txId) + } + } + async AddPendingUserToUserPayment(fromUserId: string, toUserId: string, amount: number, fee: number, linkedApplication: Application, txId: string) { return this.dbs.CreateAndSave('UserToUserPayment', { from_user: await this.userStorage.GetUser(fromUserId, txId),