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:
case GdtEntryType.DIGISTORE:
case GdtEntryType.CVS2: {
return {
icon: 'heart', icon: 'heart',
iconclasses: 'gradido-global-color-accent m-mb-1 font2em', iconclasses: 'gradido-global-color-accent m-mb-1 font2em',
description: this.$t('gdt.contribution'), description: this.$t('gdt.contribution'),
descriptiontext: this.$n(this.amount, 'decimal') + ' €', descriptiontext: this.$n(this.amount, 'decimal') + ' €',
credittext: this.$n(this.gdt, 'decimal') + ' GDT', credittext: this.$n(this.gdt, 'decimal') + ' GDT',
}, }
4: { }
case GdtEntryType.ELOPAGE_PUBLISHER: {
return {
icon: 'person-check', icon: 'person-check',
iconclasses: 'gradido-global-color-accent m-mb-1 font2em', iconclasses: 'gradido-global-color-accent m-mb-1 font2em',
description: this.$t('gdt.recruited-member'), description: this.$t('gdt.recruited-member'),
descriptiontext: '5%', descriptiontext: '5%',
credittext: this.$n(this.amount, 'decimal') + ' GDT', credittext: this.$n(this.amount, 'decimal') + ' GDT',
}, }
7: { }
case GdtEntryType.GLOBAL_MODIFICATOR: {
return {
icon: 'gift', icon: 'gift',
iconclasses: 'gradido-global-color-accent m-mb-1 font2em', iconclasses: 'gradido-global-color-accent m-mb-1 font2em',
description: this.$t('gdt.gdt-received'), description: this.$t('gdt.gdt-received'),
descriptiontext: this.comment, descriptiontext: this.comment,
credittext: this.$n(this.gdt, 'decimal') + ' GDT', credittext: this.$n(this.gdt, 'decimal') + ' GDT',
},
} }
}
const type = linesByType[givenType] default:
if (type) return type
throw new Error('no lines for this type: ' + givenType) throw new Error('no lines for this type: ' + givenType)
}
}, },
}, },
} }

View File

@ -23,20 +23,25 @@
</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:
case GdtEntryType.DIGISTORE:
case GdtEntryType.CVS2: {
return {
headline: this.$t('gdt.calculation'), headline: this.$t('gdt.calculation'),
first: this.$t('gdt.factor'), first: this.$t('gdt.factor'),
firstMath: this.factor + ' GDT pro €', firstMath: this.factor + ' GDT pro €',
@ -48,15 +53,19 @@ export default {
' GDT / € = ' + ' GDT / € = ' +
this.$n(this.gdt, 'decimal') + this.$n(this.gdt, 'decimal') +
' GDT', ' GDT',
}, }
4: { }
case GdtEntryType.ELOPAGE_PUBLISHER: {
return {
headline: this.$t('gdt.publisher'), headline: this.$t('gdt.publisher'),
first: null, first: null,
firstMath: null, firstMath: null,
second: null, second: null,
secondMath: null, secondMath: null,
}, }
7: { }
case GdtEntryType.GLOBAL_MODIFICATOR: {
return {
headline: this.$t('gdt.conversion-gdt-euro'), headline: this.$t('gdt.conversion-gdt-euro'),
first: this.$t('gdt.raise'), first: this.$t('gdt.raise'),
firstMath: this.factor * 100 + ' % ', firstMath: this.factor * 100 + ' % ',
@ -68,13 +77,11 @@ export default {
' % = ' + ' % = ' +
this.$n(this.gdt, 'decimal') + this.$n(this.gdt, 'decimal') +
' GDT', ' GDT',
},
} }
}
const type = linesByType[givenType] default:
if (type) return type
throw new Error('no additional transaction info for this type: ' + givenType) 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' 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', () => {