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) {
throw new Error(resultGDT.data)
}
console.log(resultGDT.data)
return new GdtEntryList(resultGDT.data)
}
}

View File

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

View File

@ -23,20 +23,25 @@
</div>
</template>
<script>
import { GdtEntryType } from '../graphql/enums'
export default {
name: 'TransactionCollapse',
props: {
amount: { type: Number },
gdtEntryType: { type: Number, default: 1 },
gdtEntryType: { type: String, default: GdtEntryType.FORM },
factor: { type: Number },
gdt: { type: Number },
},
methods: {
getLinesByType(givenType) {
if (givenType === 2 || givenType === 3 || givenType === 5 || givenType === 6) givenType = 1
const linesByType = {
1: {
switch (givenType) {
case GdtEntryType.FORM:
case GdtEntryType.CVS:
case GdtEntryType.ELOPAGE:
case GdtEntryType.DIGISTORE:
case GdtEntryType.CVS2: {
return {
headline: this.$t('gdt.calculation'),
first: this.$t('gdt.factor'),
firstMath: this.factor + ' GDT pro €',
@ -48,15 +53,19 @@ export default {
' GDT / € = ' +
this.$n(this.gdt, 'decimal') +
' GDT',
},
4: {
}
}
case GdtEntryType.ELOPAGE_PUBLISHER: {
return {
headline: this.$t('gdt.publisher'),
first: null,
firstMath: null,
second: null,
secondMath: null,
},
7: {
}
}
case GdtEntryType.GLOBAL_MODIFICATOR: {
return {
headline: this.$t('gdt.conversion-gdt-euro'),
first: this.$t('gdt.raise'),
firstMath: this.factor * 100 + ' % ',
@ -68,13 +77,11 @@ export default {
' % = ' +
this.$n(this.gdt, 'decimal') +
' GDT',
},
}
const type = linesByType[givenType]
if (type) return type
}
default:
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,15 +1,7 @@
import { mutations, actions } from './store'
const {
language,
email,
token,
username,
firstName,
lastName,
description,
newsletterState,
} = mutations
const { language, email, token, username, firstName, lastName, description, newsletterState } =
mutations
const { login, logout } = actions
describe('Vuex store', () => {