mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
first try with disbursement result from queryTransactionLink
This commit is contained in:
parent
6d8a65a138
commit
fddfe69bad
49
backend/src/graphql/model/DisbursementLink.ts
Normal file
49
backend/src/graphql/model/DisbursementLink.ts
Normal file
@ -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
|
||||
}
|
||||
@ -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<typeof QueryLinkResult> {
|
||||
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])
|
||||
|
||||
@ -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
|
||||
},
|
||||
})
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
:link-data="linkData"
|
||||
:redeem-code="redeemCode"
|
||||
:is-contribution-link="isContributionLink"
|
||||
:is-disbursement-link="isDisbursementLink"
|
||||
class="redeem-community-selection"
|
||||
>
|
||||
<BCard bg-variant="muted" text-variant="dark" border-variant="info">
|
||||
@ -13,7 +14,7 @@
|
||||
<BCol>{{ $t('gdd_per_link.recipientCommunity') }}</BCol>
|
||||
</BRow>
|
||||
<h3>
|
||||
<BRow>
|
||||
<BRow v-if="!isDisbursementLink">
|
||||
<BCol class="fw-bold">
|
||||
<community-switch
|
||||
:disabled="isBalanceDisabled"
|
||||
@ -49,6 +50,7 @@ const props = defineProps({
|
||||
linkData: { type: Object, required: true },
|
||||
redeemCode: { type: String, required: true },
|
||||
isContributionLink: { type: Boolean, default: false },
|
||||
isDisbursementLink: { type: Boolean, default: false },
|
||||
receiverCommunity: {
|
||||
type: Object,
|
||||
required: false,
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
:link-data="props.linkData"
|
||||
:redeem-code="props.redeemCode"
|
||||
:is-contribution-link="props.isContributionLink"
|
||||
:is-disbursement-link="props.isDisbursementLink"
|
||||
/>
|
||||
|
||||
<BCard>
|
||||
@ -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({
|
||||
|
||||
@ -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
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
:link-data="linkData"
|
||||
:redeem-code="redeemCode"
|
||||
:is-contribution-link="isContributionLink"
|
||||
:is-disbursement-link="isDisbursementLink"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@ -18,6 +19,7 @@
|
||||
<redeem-valid
|
||||
:link-data="linkData"
|
||||
:is-contribution-link="isContributionLink"
|
||||
:is-disbursement-link="isDisbursementLink"
|
||||
:valid-link="validLink"
|
||||
@mutation-link="mutationLink"
|
||||
/>
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user