update GDT to use enums and switch-case

This commit is contained in:
einhorn_b 2021-10-02 16:41:21 +02:00
parent cc4571e4d3
commit 2630de425d
7 changed files with 116 additions and 97 deletions

View File

@ -30,7 +30,7 @@ export class GdtResolver {
if (!resultGDT.success) { if (!resultGDT.success) {
throw new Error(resultGDT.data) throw new Error(resultGDT.data)
} }
console.log(resultGDT.data)
return new GdtEntryList(resultGDT.data) return new GdtEntryList(resultGDT.data)
} }
} }

View File

@ -38,7 +38,7 @@
</b-row> </b-row>
<!-- Message--> <!-- Message-->
<b-row v-if="comment && gdtEntryType !== 7"> <b-row v-if="comment && !isGlobalModificator">
<b-col cols="6" class="text-right"> <b-col cols="6" class="text-right">
{{ $t('form.memo') }} {{ $t('form.memo') }}
</b-col> </b-col>
@ -72,6 +72,7 @@
</template> </template>
<script> <script>
import TransactionCollapse from './TransactionCollapse.vue' import TransactionCollapse from './TransactionCollapse.vue'
import { GdtEntryType } from '../graphql/enums'
export default { export default {
name: 'Transaction', name: 'Transaction',
@ -82,42 +83,52 @@ export default {
amount: { type: Number }, amount: { type: Number },
date: { type: String }, date: { type: String },
comment: { type: String }, comment: { type: String },
gdtEntryType: { type: Number, default: 1 }, gdtEntryType: { type: String, default: GdtEntryType.FORM },
factor: { type: Number }, factor: { type: Number },
gdt: { type: Number }, gdt: { type: Number },
}, },
computed: {
isGlobalModificator: function () {
return this.gdtEntryType === GdtEntryType.GLOBAL_MODIFICATOR
},
},
methods: { methods: {
getLinesByType(givenType) { getLinesByType(givenType) {
if (givenType === 2 || givenType === 3 || givenType === 5 || givenType === 6) givenType = 1 switch (givenType) {
case GdtEntryType.FORM:
const linesByType = { case GdtEntryType.CVS:
1: { case GdtEntryType.ELOPAGE:
icon: 'heart', case GdtEntryType.DIGISTORE:
iconclasses: 'gradido-global-color-accent m-mb-1 font2em', case GdtEntryType.CVS2: {
description: this.$t('gdt.contribution'), return {
descriptiontext: this.$n(this.amount, 'decimal') + ' €', icon: 'heart',
credittext: this.$n(this.gdt, 'decimal') + ' GDT', iconclasses: 'gradido-global-color-accent m-mb-1 font2em',
}, description: this.$t('gdt.contribution'),
4: { descriptiontext: this.$n(this.amount, 'decimal') + ' €',
icon: 'person-check', credittext: this.$n(this.gdt, 'decimal') + ' GDT',
iconclasses: 'gradido-global-color-accent m-mb-1 font2em', }
description: this.$t('gdt.recruited-member'), }
descriptiontext: '5%', case GdtEntryType.ELOPAGE_PUBLISHER: {
credittext: this.$n(this.amount, 'decimal') + ' GDT', return {
}, icon: 'person-check',
7: { iconclasses: 'gradido-global-color-accent m-mb-1 font2em',
icon: 'gift', description: this.$t('gdt.recruited-member'),
iconclasses: 'gradido-global-color-accent m-mb-1 font2em', descriptiontext: '5%',
description: this.$t('gdt.gdt-received'), credittext: this.$n(this.amount, 'decimal') + ' GDT',
descriptiontext: this.comment, }
credittext: this.$n(this.gdt, 'decimal') + ' GDT', }
}, case GdtEntryType.GLOBAL_MODIFICATOR: {
return {
icon: 'gift',
iconclasses: 'gradido-global-color-accent m-mb-1 font2em',
description: this.$t('gdt.gdt-received'),
descriptiontext: this.comment,
credittext: this.$n(this.gdt, 'decimal') + ' GDT',
}
}
default:
throw new Error('no lines for this type: ' + givenType)
} }
const type = linesByType[givenType]
if (type) return type
throw new Error('no lines for this type: ' + givenType)
}, },
}, },
} }

View File

@ -23,58 +23,65 @@
</div> </div>
</template> </template>
<script> <script>
import { GdtEntryType } from '../graphql/enums'
export default { export default {
name: 'TransactionCollapse', name: 'TransactionCollapse',
props: { props: {
amount: { type: Number }, amount: { type: Number },
gdtEntryType: { type: Number, default: 1 }, gdtEntryType: { type: String, default: GdtEntryType.FORM },
factor: { type: Number }, factor: { type: Number },
gdt: { type: Number }, gdt: { type: Number },
}, },
methods: { methods: {
getLinesByType(givenType) { getLinesByType(givenType) {
if (givenType === 2 || givenType === 3 || givenType === 5 || givenType === 6) givenType = 1 switch (givenType) {
case GdtEntryType.FORM:
const linesByType = { case GdtEntryType.CVS:
1: { case GdtEntryType.ELOPAGE:
headline: this.$t('gdt.calculation'), case GdtEntryType.DIGISTORE:
first: this.$t('gdt.factor'), case GdtEntryType.CVS2: {
firstMath: this.factor + ' GDT pro €', return {
second: this.$t('gdt.formula'), headline: this.$t('gdt.calculation'),
secondMath: first: this.$t('gdt.factor'),
this.$n(this.amount, 'decimal') + firstMath: this.factor + ' GDT pro €',
' € * ' + second: this.$t('gdt.formula'),
this.factor + secondMath:
' GDT / € = ' + this.$n(this.amount, 'decimal') +
this.$n(this.gdt, 'decimal') + ' € * ' +
' GDT', this.factor +
}, ' GDT / € = ' +
4: { this.$n(this.gdt, 'decimal') +
headline: this.$t('gdt.publisher'), ' GDT',
first: null, }
firstMath: null, }
second: null, case GdtEntryType.ELOPAGE_PUBLISHER: {
secondMath: null, return {
}, headline: this.$t('gdt.publisher'),
7: { first: null,
headline: this.$t('gdt.conversion-gdt-euro'), firstMath: null,
first: this.$t('gdt.raise'), second: null,
firstMath: this.factor * 100 + ' % ', secondMath: null,
second: this.$t('gdt.conversion'), }
secondMath: }
this.$n(this.amount, 'decimal') + case GdtEntryType.GLOBAL_MODIFICATOR: {
' GDT * ' + return {
this.factor * 100 + headline: this.$t('gdt.conversion-gdt-euro'),
' % = ' + first: this.$t('gdt.raise'),
this.$n(this.gdt, 'decimal') + firstMath: this.factor * 100 + ' % ',
' GDT', second: this.$t('gdt.conversion'),
}, secondMath:
this.$n(this.amount, 'decimal') +
' GDT * ' +
this.factor * 100 +
' % = ' +
this.$n(this.gdt, 'decimal') +
' GDT',
}
}
default:
throw new Error('no additional transaction info for this type: ' + givenType)
} }
const type = linesByType[givenType]
if (type) return type
throw new Error('no additional transaction info for this type: ' + givenType)
}, },
}, },
} }

View File

@ -0,0 +1,9 @@
export const GdtEntryType = {
FORM: 'FORM',
CVS: 'CVS',
ELOPAGE: 'ELOPAGE',
ELOPAGE_PUBLISHER: 'ELOPAGE_PUBLISHER',
DIGISTORE: 'DIGISTORE',
CVS2: 'CVS2',
GLOBAL_MODIFICATOR: 'GLOBAL_MODIFICATOR',
}

View File

@ -1,25 +1,25 @@
import gql from 'graphql-tag' import gql from 'graphql-tag'
export const subscribeNewsletter = gql` export const subscribeNewsletter = gql`
mutation($email: String!, $language: String!) { mutation ($email: String!, $language: String!) {
subscribeNewsletter(email: $email, language: $language) subscribeNewsletter(email: $email, language: $language)
} }
` `
export const unsubscribeNewsletter = gql` export const unsubscribeNewsletter = gql`
mutation($email: String!) { mutation ($email: String!) {
unsubscribeNewsletter(email: $email) unsubscribeNewsletter(email: $email)
} }
` `
export const resetPassword = gql` export const resetPassword = gql`
mutation($sessionId: Float!, $email: String!, $password: String!) { mutation ($sessionId: Float!, $email: String!, $password: String!) {
resetPassword(sessionId: $sessionId, email: $email, password: $password) resetPassword(sessionId: $sessionId, email: $email, password: $password)
} }
` `
export const updateUserInfos = gql` export const updateUserInfos = gql`
mutation( mutation (
$firstName: String $firstName: String
$lastName: String $lastName: String
$description: String $description: String
@ -45,7 +45,7 @@ export const updateUserInfos = gql`
` `
export const registerUser = gql` export const registerUser = gql`
mutation( mutation (
$firstName: String! $firstName: String!
$lastName: String! $lastName: String!
$email: String! $email: String!
@ -63,7 +63,7 @@ export const registerUser = gql`
` `
export const sendCoins = gql` export const sendCoins = gql`
mutation($email: String!, $amount: Float!, $memo: String!) { mutation ($email: String!, $amount: Float!, $memo: String!) {
sendCoins(email: $email, amount: $amount, memo: $memo) sendCoins(email: $email, amount: $amount, memo: $memo)
} }
` `

View File

@ -1,7 +1,7 @@
import gql from 'graphql-tag' import gql from 'graphql-tag'
export const login = gql` export const login = gql`
query($email: String!, $password: String!) { query ($email: String!, $password: String!) {
login(email: $email, password: $password) { login(email: $email, password: $password) {
email email
username username
@ -24,7 +24,7 @@ export const logout = gql`
` `
export const loginViaEmailVerificationCode = gql` export const loginViaEmailVerificationCode = gql`
query($optin: String!) { query ($optin: String!) {
loginViaEmailVerificationCode(optin: $optin) { loginViaEmailVerificationCode(optin: $optin) {
sessionId sessionId
email email
@ -33,7 +33,7 @@ export const loginViaEmailVerificationCode = gql`
` `
export const transactionsQuery = gql` export const transactionsQuery = gql`
query($currentPage: Int = 1, $pageSize: Int = 25, $order: Order = DESC) { query ($currentPage: Int = 1, $pageSize: Int = 25, $order: Order = DESC) {
transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) { transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) {
gdtSum gdtSum
count count
@ -64,7 +64,7 @@ export const transactionsQuery = gql`
` `
export const sendResetPasswordEmail = gql` export const sendResetPasswordEmail = gql`
query($email: String!) { query ($email: String!) {
sendResetPasswordEmail(email: $email) { sendResetPasswordEmail(email: $email) {
state state
} }
@ -72,7 +72,7 @@ export const sendResetPasswordEmail = gql`
` `
export const checkUsername = gql` export const checkUsername = gql`
query($username: String!) { query ($username: String!) {
checkUsername(username: $username) { checkUsername(username: $username) {
state state
} }
@ -80,7 +80,7 @@ export const checkUsername = gql`
` `
export const listGDTEntriesQuery = gql` export const listGDTEntriesQuery = gql`
query($currentPage: Int!, $pageSize: Int!) { query ($currentPage: Int!, $pageSize: Int!) {
listGDTEntries(currentPage: $currentPage, pageSize: $pageSize) { listGDTEntries(currentPage: $currentPage, pageSize: $pageSize) {
count count
gdtEntries { gdtEntries {
@ -98,7 +98,7 @@ export const listGDTEntriesQuery = gql`
` `
export const checkEmailQuery = gql` export const checkEmailQuery = gql`
query($optin: String!) { query ($optin: String!) {
checkEmail(optin: $optin) { checkEmail(optin: $optin) {
email email
sessionId sessionId

View File

@ -1,15 +1,7 @@
import { mutations, actions } from './store' import { mutations, actions } from './store'
const { const { language, email, token, username, firstName, lastName, description, newsletterState } =
language, mutations
email,
token,
username,
firstName,
lastName,
description,
newsletterState,
} = mutations
const { login, logout } = actions const { login, logout } = actions
describe('Vuex store', () => { describe('Vuex store', () => {