From 8ace2e105c9924d1464db8edd68c4b19a02ea5cb Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 10 Oct 2023 19:52:10 +0200 Subject: [PATCH] first draft for playing around with --- .../src/graphql/resolver/CommunityResolver.ts | 15 +++++++- .../src/graphql/resolver/util/communities.ts | 6 ++++ .../components/GddSend/TransactionForm.vue | 34 ++++++++++++++----- frontend/src/graphql/queries.js | 12 +++++++ frontend/src/pages/Send.vue | 2 +- 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index 026871780..e5da1fda6 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -1,13 +1,16 @@ import { IsNull, Not } from '@dbTools/typeorm' import { Community as DbCommunity } from '@entity/Community' import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' -import { Resolver, Query, Authorized } from 'type-graphql' +import { Resolver, Query, Authorized, Arg } from 'type-graphql' import { Community } from '@model/Community' import { FederatedCommunity } from '@model/FederatedCommunity' import { RIGHTS } from '@/auth/RIGHTS' +import { getCommunity } from './util/communities' +import { LogError } from '@/server/LogError' + @Resolver() export class CommunityResolver { @Authorized([RIGHTS.COMMUNITIES]) @@ -36,4 +39,14 @@ export class CommunityResolver { }) return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom)) } + + @Authorized([RIGHTS.COMMUNITIES]) + @Query(() => Community) + async community(@Arg('communityUuid') communityUuid: string): Promise { + const community = await getCommunity(communityUuid) + if (!community) { + throw new LogError('community not found', communityUuid) + } + return new Community(community) + } } diff --git a/backend/src/graphql/resolver/util/communities.ts b/backend/src/graphql/resolver/util/communities.ts index 52fee86b2..5854f94b0 100644 --- a/backend/src/graphql/resolver/util/communities.ts +++ b/backend/src/graphql/resolver/util/communities.ts @@ -51,3 +51,9 @@ export async function getCommunityName(communityIdentifier: string): Promise { + return await DbCommunity.findOne({ + where: [{ communityUuid }], + }) +} diff --git a/frontend/src/components/GddSend/TransactionForm.vue b/frontend/src/components/GddSend/TransactionForm.vue index 7304137ee..db1bf0d1a 100644 --- a/frontend/src/components/GddSend/TransactionForm.vue +++ b/frontend/src/components/GddSend/TransactionForm.vue @@ -55,10 +55,17 @@ - +
+ +
+
+ + {{ recipientCommunity.name }} + +
@@ -143,7 +150,7 @@ import InputIdentifier from '@/components/Inputs/InputIdentifier' import InputAmount from '@/components/Inputs/InputAmount' import InputTextarea from '@/components/Inputs/InputTextarea' import CommunitySwitch from '@/components/CommunitySwitch.vue' -import { user as userQuery } from '@/graphql/queries' +import { userAndCommunity } from '@/graphql/queries' import { isEmpty } from 'lodash' import { COMMUNITY_NAME } from '@/config' @@ -178,6 +185,7 @@ export default { }, radioSelected: this.selected, userName: '', + recipientCommunity: { uuid: '', name: '' }, } }, methods: { @@ -186,6 +194,9 @@ export default { }, onSubmit() { if (this.gradidoID) this.form.identifier = this.gradidoID + if (this.communityUuid) { + this.form.targetCommunity = this.recipientCommunity + } this.$emit('set-transaction', { selected: this.radioSelected, identifier: this.form.identifier, @@ -209,17 +220,21 @@ export default { apollo: { UserName: { query() { - return userQuery + return userAndCommunity }, fetchPolicy: 'network-only', variables() { - return { identifier: this.gradidoID } + return { + identifier: this.gradidoID, + communityUuid: this.communityUuid, + } }, skip() { return !this.gradidoID }, - update({ user }) { + update({ user, community }) { this.userName = `${user.firstName} ${user.lastName}` + this.recipientCommunity.name = community.name }, error({ message }) { this.toastError(message) @@ -247,6 +262,9 @@ export default { gradidoID() { return this.$route.query && this.$route.query.gradidoID }, + communityUuid() { + return this.$route.query && this.$route.query.communityUuid + }, }, mounted() { if (this.form.identifier !== '') this.$refs.formValidator.validate() diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 6ef5d56d6..5edbc1d1f 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -284,3 +284,15 @@ export const user = gql` } } ` + +export const userAndCommunity = gql` + query($identifier: String!, $communityUuid: String!) { + user(identifier: $identifier) { + firstName + lastName + } + community(communityUuid: $communityUuid) { + name + } + } +` diff --git a/frontend/src/pages/Send.vue b/frontend/src/pages/Send.vue index 607c7e36c..1f0c1f264 100644 --- a/frontend/src/pages/Send.vue +++ b/frontend/src/pages/Send.vue @@ -172,7 +172,7 @@ export default { throw new Error(`undefined transactionData.selected : ${this.transactionData.selected}`) } this.loading = false - this.$router.push({ query: { gradidoID: undefined } }) + this.$router.push({ query: { gradidoID: undefined, communityUuid: undefined } }) }, onBack() { this.currentTransactionStep = TRANSACTION_STEPS.transactionForm