mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
sender alias as optional and further optimizations
This commit is contained in:
parent
8a9a539e3c
commit
e983e59173
@ -27,6 +27,6 @@ export class SendCoinsArgs {
|
||||
@Field(() => String)
|
||||
senderUserName: string
|
||||
|
||||
@Field(() => String)
|
||||
senderAlias: string
|
||||
@Field(() => String, { nullable: true })
|
||||
senderAlias?: string | null
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ import { calculateBalance } from '@/util/validate'
|
||||
import { virtualLinkTransaction, virtualDecayTransaction } from '@/util/virtualTransactions'
|
||||
|
||||
import { BalanceResolver } from './BalanceResolver'
|
||||
import { getCommunityName, isCommunityAuthenticated, isHomeCommunity } from './util/communities'
|
||||
import { getCommunity, getCommunityName, isHomeCommunity } from './util/communities'
|
||||
import { findUserByIdentifier } from './util/findUserByIdentifier'
|
||||
import { getLastTransaction } from './util/getLastTransaction'
|
||||
import { getTransactionList } from './util/getTransactionList'
|
||||
@ -445,13 +445,17 @@ export class TransactionResolver {
|
||||
if (!CONFIG.FEDERATION_XCOM_SENDCOINS_ENABLED) {
|
||||
throw new LogError('X-Community sendCoins disabled per configuration!')
|
||||
}
|
||||
if (!(await isCommunityAuthenticated(recipientCommunityIdentifier))) {
|
||||
const recipCom = await getCommunity(recipientCommunityIdentifier)
|
||||
logger.debug('recipient commuity: ', recipCom)
|
||||
if (recipCom === null) {
|
||||
throw new LogError(
|
||||
'no recipient commuity found for identifier:',
|
||||
recipientCommunityIdentifier,
|
||||
)
|
||||
}
|
||||
if (recipCom !== null && recipCom.authenticatedAt === null) {
|
||||
throw new LogError('recipient commuity is connected, but still not authenticated yet!')
|
||||
}
|
||||
const recipCom = await DbCommunity.findOneOrFail({
|
||||
where: { communityUuid: recipientCommunityIdentifier },
|
||||
})
|
||||
logger.debug('recipient commuity: ', recipCom)
|
||||
let pendingResult: SendCoinsResult
|
||||
let committingResult: SendCoinsResult
|
||||
const creationDate = new Date()
|
||||
|
||||
@ -27,6 +27,6 @@ export class SendCoinsArgs {
|
||||
@Field(() => String)
|
||||
senderUserName: string
|
||||
|
||||
@Field(() => String)
|
||||
senderAlias: string
|
||||
@Field(() => String, { nullable: true })
|
||||
senderAlias?: string | null
|
||||
}
|
||||
|
||||
@ -35,11 +35,13 @@ export class SendCoinsResolver {
|
||||
args.senderCommunityUuid,
|
||||
args.senderUserUuid,
|
||||
args.senderUserName,
|
||||
args.senderAlias,
|
||||
)
|
||||
const result = new SendCoinsResult()
|
||||
// first check if receiver community is correct
|
||||
const homeCom = await DbCommunity.findOneBy({
|
||||
communityUuid: args.recipientCommunityUuid,
|
||||
foreign: false,
|
||||
})
|
||||
if (!homeCom) {
|
||||
throw new LogError(
|
||||
@ -50,7 +52,10 @@ export class SendCoinsResolver {
|
||||
let receiverUser
|
||||
try {
|
||||
// second check if receiver user exists in this community
|
||||
receiverUser = await findUserByIdentifier(args.recipientUserIdentifier)
|
||||
receiverUser = await findUserByIdentifier(
|
||||
args.recipientUserIdentifier,
|
||||
args.recipientCommunityUuid,
|
||||
)
|
||||
} catch (err) {
|
||||
logger.error('Error in findUserByIdentifier:', err)
|
||||
throw new LogError(
|
||||
|
||||
@ -6,12 +6,18 @@ import { LogError } from '@/server/LogError'
|
||||
|
||||
import { VALID_ALIAS_REGEX } from './validateAlias'
|
||||
|
||||
export const findUserByIdentifier = async (identifier: string): Promise<DbUser> => {
|
||||
export const findUserByIdentifier = async (
|
||||
identifier: string,
|
||||
communityIdentifier?: string,
|
||||
): Promise<DbUser> => {
|
||||
let user: DbUser | null
|
||||
if (validate(identifier) && version(identifier) === 4) {
|
||||
user = await DbUser.findOne({ where: { gradidoID: identifier }, relations: ['emailContact'] })
|
||||
user = await DbUser.findOne({
|
||||
where: { gradidoID: identifier, communityUuid: communityIdentifier },
|
||||
relations: ['emailContact'],
|
||||
})
|
||||
if (!user) {
|
||||
throw new LogError('No user found to given identifier', identifier)
|
||||
throw new LogError('No user found to given identifier(s)', identifier, communityIdentifier)
|
||||
}
|
||||
} else if (/^.{2,}@.{2,}\..{2,}$/.exec(identifier)) {
|
||||
const userContact = await DbUserContact.findOne({
|
||||
@ -27,12 +33,22 @@ export const findUserByIdentifier = async (identifier: string): Promise<DbUser>
|
||||
if (!userContact.user) {
|
||||
throw new LogError('No user to given contact', identifier)
|
||||
}
|
||||
if (userContact.user.communityUuid !== communityIdentifier) {
|
||||
throw new LogError(
|
||||
'Found user to given contact, but belongs to other community',
|
||||
identifier,
|
||||
communityIdentifier,
|
||||
)
|
||||
}
|
||||
user = userContact.user
|
||||
user.emailContact = userContact
|
||||
} else if (VALID_ALIAS_REGEX.exec(identifier)) {
|
||||
user = await DbUser.findOne({ where: { alias: identifier }, relations: ['emailContact'] })
|
||||
user = await DbUser.findOne({
|
||||
where: { alias: identifier, communityUuid: communityIdentifier },
|
||||
relations: ['emailContact'],
|
||||
})
|
||||
if (!user) {
|
||||
throw new LogError('No user found to given identifier', identifier)
|
||||
throw new LogError('No user found to given identifier(s)', identifier, communityIdentifier)
|
||||
}
|
||||
} else {
|
||||
throw new LogError('Unknown identifier type', identifier)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user