From fddfe69bad4ef1c2a2a81abbbf31c92e174b07df Mon Sep 17 00:00:00 2001
From: clauspeterhuebner
Date: Thu, 17 Apr 2025 16:00:47 +0200
Subject: [PATCH] first try with disbursement result from queryTransactionLink
---
backend/src/graphql/model/DisbursementLink.ts | 49 +++++++++++++++++++
.../resolver/TransactionLinkResolver.ts | 19 +++----
backend/src/graphql/union/QueryLinkResult.ts | 9 +++-
.../RedeemCommunitySelection.vue | 4 +-
.../RedeemSelectCommunity.vue | 2 +
frontend/src/graphql/queries.js | 19 +++++++
frontend/src/pages/TransactionLink.vue | 29 ++++++++++-
7 files changed, 117 insertions(+), 14 deletions(-)
create mode 100644 backend/src/graphql/model/DisbursementLink.ts
diff --git a/backend/src/graphql/model/DisbursementLink.ts b/backend/src/graphql/model/DisbursementLink.ts
new file mode 100644
index 000000000..acbc584c9
--- /dev/null
+++ b/backend/src/graphql/model/DisbursementLink.ts
@@ -0,0 +1,49 @@
+import { Decimal } from 'decimal.js-light'
+import { ObjectType, Field } from 'type-graphql'
+
+import { DisbursementJwtPayloadType } from '@/auth/jwt/payloadtypes/DisbursementJwtPayloadType'
+
+import { Community } from './Community'
+import { User } from './User'
+
+@ObjectType()
+export class DisbursementLink {
+ constructor(
+ disbursementPayload: DisbursementJwtPayloadType,
+ recipientCommunity: Community,
+ recipientUser?: User,
+ ) {
+ this.recipientCommunity = recipientCommunity
+ if (recipientUser !== undefined) {
+ this.recipientUser = recipientUser
+ } else {
+ this.recipientUser = null
+ }
+ this.senderGradidoID = disbursementPayload.sendergradidoid
+ this.senderName = disbursementPayload.sendername
+ this.amount = new Decimal(disbursementPayload.amount)
+ this.memo = disbursementPayload.memo
+ this.code = disbursementPayload.redeemcode
+ }
+
+ @Field(() => Community)
+ recipientCommunity: Community
+
+ @Field(() => User, { nullable: true })
+ recipientUser: User | null
+
+ @Field(() => String)
+ senderGradidoID: string
+
+ @Field(() => String)
+ senderName: string
+
+ @Field(() => Decimal)
+ amount: Decimal
+
+ @Field(() => String)
+ memo: string
+
+ @Field(() => String)
+ code: string
+}
diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts
index 207fe5a29..68a385e47 100644
--- a/backend/src/graphql/resolver/TransactionLinkResolver.ts
+++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts
@@ -17,6 +17,7 @@ import { ContributionCycleType } from '@enum/ContributionCycleType'
import { ContributionStatus } from '@enum/ContributionStatus'
import { ContributionType } from '@enum/ContributionType'
import { TransactionTypeId } from '@enum/TransactionTypeId'
+import { Community } from '@model/Community'
import { ContributionLink } from '@model/ContributionLink'
import { Decay } from '@model/Decay'
import { TransactionLink, TransactionLinkResult } from '@model/TransactionLink'
@@ -51,6 +52,7 @@ import { getUserCreation, validateContribution } from './util/creations'
import { getLastTransaction } from './util/getLastTransaction'
import { sendTransactionsToDltConnector } from './util/sendTransactionsToDltConnector'
import { transactionLinkList } from './util/transactionLinkList'
+import { DisbursementLink } from '../model/DisbursementLink'
// TODO: do not export, test it inside the resolver
export const transactionLinkCode = (date: Date): string => {
@@ -145,7 +147,6 @@ export class TransactionLinkResolver {
@Query(() => QueryLinkResult)
async queryTransactionLink(@Arg('code') code: string): Promise {
logger.debug('TransactionLinkResolver.queryTransactionLink... code=', code)
- const transactionLink = new TransactionLink()
if (code.match(/^CL-/)) {
const contributionLink = await DbContributionLink.findOneOrFail({
where: { code: code.replace('CL-', '') },
@@ -246,23 +247,19 @@ export class TransactionLinkResolver {
'TransactionLinkResolver.queryTransactionLink... nach decode verifiedPayload=',
verifiedPayload,
)
- transactionLink.communityName = senderCom.name !== null ? senderCom.name : 'unknown'
- transactionLink.user = new User(null)
- transactionLink.user.alias = verifiedPayload.sendername
- transactionLink.amount = new Decimal(verifiedPayload.amount)
- transactionLink.memo = verifiedPayload.memo
- transactionLink.code = verifiedPayload.redeemcode
+ const homeCommunity = await getHomeCommunity()
+ const recipientCommunity = new Community(homeCommunity)
+ const disbursementLink = new DisbursementLink(verifiedPayload, recipientCommunity)
logger.debug(
- 'TransactionLinkResolver.queryTransactionLink... transactionLink=',
- transactionLink,
+ 'TransactionLinkResolver.queryTransactionLink... disbursementLink=',
+ disbursementLink,
)
- return transactionLink
+ return disbursementLink
} else {
throw new LogError('Redeem with wrong type of JWT-Token! decodedPayload=', decodedPayload)
}
}
}
- return transactionLink
}
@Authorized([RIGHTS.REDEEM_TRANSACTION_LINK])
diff --git a/backend/src/graphql/union/QueryLinkResult.ts b/backend/src/graphql/union/QueryLinkResult.ts
index fdf1c7b17..e1059a83d 100644
--- a/backend/src/graphql/union/QueryLinkResult.ts
+++ b/backend/src/graphql/union/QueryLinkResult.ts
@@ -1,9 +1,16 @@
import { createUnionType } from 'type-graphql'
import { ContributionLink } from '@model/ContributionLink'
+import { DisbursementLink } from '@model/DisbursementLink'
import { TransactionLink } from '@model/TransactionLink'
export const QueryLinkResult = createUnionType({
name: 'QueryLinkResult', // the name of the GraphQL union
- types: () => [TransactionLink, ContributionLink] as const, // function that returns tuple of object types classes
+ types: () => [TransactionLink, DisbursementLink, ContributionLink] as const, // function that returns tuple of object types classes
+ resolveType: (value: TransactionLink | DisbursementLink | ContributionLink) => {
+ if (value instanceof TransactionLink) return TransactionLink
+ if (value instanceof DisbursementLink) return DisbursementLink
+ if (value instanceof ContributionLink) return ContributionLink
+ return null
+ },
})
diff --git a/frontend/src/components/LinkInformations/RedeemCommunitySelection.vue b/frontend/src/components/LinkInformations/RedeemCommunitySelection.vue
index 5ae6b69fe..4b6e857aa 100644
--- a/frontend/src/components/LinkInformations/RedeemCommunitySelection.vue
+++ b/frontend/src/components/LinkInformations/RedeemCommunitySelection.vue
@@ -3,6 +3,7 @@
:link-data="linkData"
:redeem-code="redeemCode"
:is-contribution-link="isContributionLink"
+ :is-disbursement-link="isDisbursementLink"
class="redeem-community-selection"
>
@@ -13,7 +14,7 @@
{{ $t('gdd_per_link.recipientCommunity') }}
-
+
@@ -40,6 +41,7 @@ const props = defineProps({
linkData: { type: Object, required: true },
redeemCode: { type: String, required: true },
isContributionLink: { type: Boolean, default: false },
+ isDisbursementLink: { type: Boolean, default: false },
})
const receiverCommunity = ref({
diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js
index bc4755776..d8ad0e2dd 100644
--- a/frontend/src/graphql/queries.js
+++ b/frontend/src/graphql/queries.js
@@ -151,6 +151,25 @@ export const queryTransactionLink = gql`
uuid
}
}
+ ... on DisbursementLink {
+ recipientCommunity {
+ foreign
+ name
+ description
+ url
+ uuid
+ }
+ recipientUser {
+ gradidoID
+ firstName
+ publisherId
+ }
+ senderGradidoID
+ senderName
+ amount
+ memo
+ code
+ }
... on ContributionLink {
id
validTo
diff --git a/frontend/src/pages/TransactionLink.vue b/frontend/src/pages/TransactionLink.vue
index 8c0f2a56c..c618672d0 100644
--- a/frontend/src/pages/TransactionLink.vue
+++ b/frontend/src/pages/TransactionLink.vue
@@ -7,6 +7,7 @@
:link-data="linkData"
:redeem-code="redeemCode"
:is-contribution-link="isContributionLink"
+ :is-disbursement-link="isDisbursementLink"
/>
@@ -18,6 +19,7 @@
@@ -81,6 +83,13 @@ const isContributionLink = computed(() => {
return params.code?.search(/^CL-/) === 0
})
+const isDisbursementLink = computed(() => {
+ if (result?.value?.__typename === 'DisbursementLink') {
+ return true
+ }
+ return false
+})
+
const redeemCode = computed(() => params.code)
const tokenExpiresInSeconds = computed(() => {
@@ -172,7 +181,13 @@ onMounted(() => {
onResult(() => {
console.log('TransactionLink.onResult... result=', result)
if (!result || !result.value) return
- setTransactionLinkInformation()
+ if (result.value.__typename === 'TransactionLink') {
+ console.log('TransactionLink.onResult... redeeming')
+ setTransactionLinkInformation()
+ } else if (result.value.__typename === 'DisbursementLink') {
+ console.log('TransactionLink.onResult... disbursing')
+ setDisbursementLinkInformation()
+ }
})
onError(() => {
@@ -196,6 +211,18 @@ function setTransactionLinkInformation() {
}
}
}
+function setDisbursementLinkInformation() {
+ console.log('TransactionLink.setDisbursementLinkInformation... result=', result)
+ const { queryDisbursementLink } = result.value
+ console.log(
+ 'TransactionLink.setDisbursementLinkInformation... queryDisbursementLink=',
+ queryDisbursementLink,
+ )
+ if (queryDisbursementLink) {
+ linkData.value = queryDisbursementLink
+ console.log('TransactionLink.setDisbursementLinkInformation... linkData.value=', linkData.value)
+ }
+}
async function mutationLink(amount) {
console.log('TransactionLink.mutationLink... params=', params)