mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
insert in transactionList the remoteUser of X-Com-Tx
This commit is contained in:
parent
f4e2588d0e
commit
d5be82ad7e
@ -5,24 +5,26 @@ import { KlickTipp } from './KlickTipp'
|
||||
|
||||
@ObjectType()
|
||||
export class User {
|
||||
constructor(user: dbUser) {
|
||||
this.id = user.id
|
||||
this.gradidoID = user.gradidoID
|
||||
this.alias = user.alias
|
||||
if (user.emailContact) {
|
||||
this.emailChecked = user.emailContact.emailChecked
|
||||
constructor(user: dbUser | null) {
|
||||
if (user) {
|
||||
this.id = user.id
|
||||
this.gradidoID = user.gradidoID
|
||||
this.alias = user.alias
|
||||
if (user.emailContact) {
|
||||
this.emailChecked = user.emailContact.emailChecked
|
||||
}
|
||||
this.firstName = user.firstName
|
||||
this.lastName = user.lastName
|
||||
this.deletedAt = user.deletedAt
|
||||
this.createdAt = user.createdAt
|
||||
this.language = user.language
|
||||
this.publisherId = user.publisherId
|
||||
this.roles = user.userRoles?.map((userRole) => userRole.role) ?? []
|
||||
this.klickTipp = null
|
||||
this.hasElopage = null
|
||||
this.hideAmountGDD = user.hideAmountGDD
|
||||
this.hideAmountGDT = user.hideAmountGDT
|
||||
}
|
||||
this.firstName = user.firstName
|
||||
this.lastName = user.lastName
|
||||
this.deletedAt = user.deletedAt
|
||||
this.createdAt = user.createdAt
|
||||
this.language = user.language
|
||||
this.publisherId = user.publisherId
|
||||
this.roles = user.userRoles?.map((userRole) => userRole.role) ?? []
|
||||
this.klickTipp = null
|
||||
this.hasElopage = null
|
||||
this.hideAmountGDD = user.hideAmountGDD
|
||||
this.hideAmountGDT = user.hideAmountGDT
|
||||
}
|
||||
|
||||
@Field(() => Int)
|
||||
|
||||
@ -38,7 +38,7 @@ import { calculateBalance } from '@/util/validate'
|
||||
import { virtualLinkTransaction, virtualDecayTransaction } from '@/util/virtualTransactions'
|
||||
|
||||
import { BalanceResolver } from './BalanceResolver'
|
||||
import { isCommunityAuthenticated, isHomeCommunity } from './util/communities'
|
||||
import { getCommunityName, isCommunityAuthenticated, isHomeCommunity } from './util/communities'
|
||||
import { findUserByIdentifier } from './util/findUserByIdentifier'
|
||||
import { getLastTransaction } from './util/getLastTransaction'
|
||||
import { getTransactionList } from './util/getTransactionList'
|
||||
@ -249,12 +249,21 @@ export class TransactionResolver {
|
||||
|
||||
// find involved users; I am involved
|
||||
const involvedUserIds: number[] = [user.id]
|
||||
const involvedRemoteUsers: User[] = []
|
||||
userTransactions.forEach((transaction: dbTransaction) => {
|
||||
if (transaction.linkedUserId && !involvedUserIds.includes(transaction.linkedUserId)) {
|
||||
involvedUserIds.push(transaction.linkedUserId)
|
||||
}
|
||||
if (!transaction.linkedUserId && transaction.linkedUserGradidoID) {
|
||||
const remoteUser = new User(null)
|
||||
remoteUser.gradidoID = transaction.linkedUserGradidoID
|
||||
remoteUser.firstName = transaction.linkedUserName
|
||||
remoteUser.lastName = transaction.linkedUserCommunityUuid
|
||||
involvedRemoteUsers.push(remoteUser)
|
||||
}
|
||||
})
|
||||
logger.debug(`involvedUserIds=${involvedUserIds}`)
|
||||
logger.debug(`involvedUserIds=`, involvedUserIds)
|
||||
logger.debug(`involvedRemoteUsers=`, involvedRemoteUsers)
|
||||
|
||||
// We need to show the name for deleted users for old transactions
|
||||
const involvedDbUsers = await dbUser.find({
|
||||
@ -263,7 +272,7 @@ export class TransactionResolver {
|
||||
relations: ['emailContact'],
|
||||
})
|
||||
const involvedUsers = involvedDbUsers.map((u) => new User(u))
|
||||
logger.debug(`involvedUsers=${involvedUsers}`)
|
||||
logger.debug(`involvedUsers=`, involvedUsers)
|
||||
|
||||
const self = new User(user)
|
||||
const transactions: Transaction[] = []
|
||||
@ -333,10 +342,25 @@ export class TransactionResolver {
|
||||
|
||||
// transactions
|
||||
userTransactions.forEach((userTransaction: dbTransaction) => {
|
||||
/*
|
||||
const linkedUser =
|
||||
userTransaction.typeId === TransactionTypeId.CREATION
|
||||
? communityUser
|
||||
: involvedUsers.find((u) => u.id === userTransaction.linkedUserId)
|
||||
*/
|
||||
let linkedUser: User | undefined
|
||||
if (userTransaction.typeId === TransactionTypeId.CREATION) {
|
||||
linkedUser = communityUser
|
||||
logger.debug('CREATION-linkedUser=', linkedUser)
|
||||
} else if (userTransaction.linkedUserId) {
|
||||
linkedUser = involvedUsers.find((u) => u.id === userTransaction.linkedUserId)
|
||||
logger.debug('local linkedUser=', linkedUser)
|
||||
} else if (userTransaction.linkedUserCommunityUuid) {
|
||||
linkedUser = involvedRemoteUsers.find(
|
||||
(u) => u.gradidoID === userTransaction.linkedUserGradidoID,
|
||||
)
|
||||
logger.debug('remote linkedUser=', linkedUser)
|
||||
}
|
||||
transactions.push(new Transaction(userTransaction, self, linkedUser))
|
||||
})
|
||||
logger.debug(`TransactionTypeId.CREATION: transactions=${transactions}`)
|
||||
|
||||
@ -40,3 +40,14 @@ export async function isCommunityAuthenticated(communityIdentifier: string): Pro
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCommunityName(communityIdentifier: string): Promise<string> {
|
||||
const community = await DbCommunity.findOne({
|
||||
where: [{ communityUuid: communityIdentifier }, { url: communityIdentifier }],
|
||||
})
|
||||
if (community?.name) {
|
||||
return community.name
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import { Community as DbCommunity } from '@entity/Community'
|
||||
import { PendingTransaction as DbPendingTransaction } from '@entity/PendingTransaction'
|
||||
import { Transaction as dbTransaction } from '@entity/Transaction'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
|
||||
import { PendingTransactionState } from '@/graphql/enum/PendingTransactionState'
|
||||
import { LogError } from '@/server/LogError'
|
||||
@ -15,7 +16,6 @@ import { calculateSenderBalance } from '@/util/calculateSenderBalance'
|
||||
import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK'
|
||||
|
||||
import { getLastTransaction } from './getLastTransaction'
|
||||
import Decimal from 'decimal.js-light'
|
||||
|
||||
export async function settlePendingSenderTransaction(
|
||||
homeCom: DbCommunity,
|
||||
@ -66,6 +66,7 @@ export async function settlePendingSenderTransaction(
|
||||
transactionSend.userGradidoID = pendingTx.userGradidoID
|
||||
transactionSend.userName = pendingTx.userName
|
||||
transactionSend.linkedUserId = pendingTx.linkedUserId
|
||||
transactionSend.linkedUserCommunityUuid = pendingTx.linkedUserCommunityUuid
|
||||
transactionSend.linkedUserGradidoID = pendingTx.linkedUserGradidoID
|
||||
transactionSend.linkedUserName = pendingTx.linkedUserName
|
||||
transactionSend.amount = pendingTx.amount
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user