first draft for playing around with

This commit is contained in:
einhorn_b 2023-10-10 19:52:10 +02:00
parent fe21c8f489
commit 8ace2e105c
5 changed files with 59 additions and 10 deletions

View File

@ -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<Community> {
const community = await getCommunity(communityUuid)
if (!community) {
throw new LogError('community not found', communityUuid)
}
return new Community(community)
}
}

View File

@ -51,3 +51,9 @@ export async function getCommunityName(communityIdentifier: string): Promise<str
return ''
}
}
export async function getCommunity(communityUuid: string): Promise<DbCommunity | null> {
return await DbCommunity.findOne({
where: [{ communityUuid }],
})
}

View File

@ -55,10 +55,17 @@
</b-row>
<b-row>
<b-col class="font-weight-bold">
<community-switch
v-model="form.targetCommunity"
:disabled="isBalanceDisabled"
/>
<div v-if="!communityUuid">
<community-switch
v-model="form.targetCommunity"
:disabled="isBalanceDisabled"
/>
</div>
<div v-else class="mb-4">
<b-row>
<b-col class="font-weight-bold">{{ recipientCommunity.name }}</b-col>
</b-row>
</div>
</b-col>
</b-row>
</b-col>
@ -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()

View File

@ -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
}
}
`

View File

@ -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