Fix several problems with admins setting of donations info

- Use 'toString' to care for setting the values of the donation progress bar.
This commit is contained in:
Wolfgang Huß 2021-06-15 13:55:08 +02:00
parent 621b3f5e8d
commit af5e255aad
6 changed files with 62 additions and 27 deletions

View File

@ -20,7 +20,6 @@ export default makeAugmentedSchema({
'FILED',
'REVIEWED',
'Report',
'Donations',
],
},
mutation: false,

View File

@ -1,4 +1,32 @@
export default {
Query: {
Donations: async (_parent, _params, context, _resolveInfo) => {
const { driver } = context
let donations
const session = driver.session()
const writeTxResultPromise = session.writeTransaction(async (txc) => {
const donationsTransactionResponse = await txc.run(
`
MATCH (donations:Donations)
WITH donations LIMIT 1
RETURN donations
`,
{},
)
return donationsTransactionResponse.records.map(
(record) => record.get('donations').properties,
)
})
try {
const txResult = await writeTxResultPromise
if (!txResult[0]) return null
donations = txResult[0]
} finally {
session.close()
}
return donations
},
},
Mutation: {
UpdateDonations: async (_parent, params, context, _resolveInfo) => {
const { driver } = context

View File

@ -8,7 +8,7 @@ type Donations {
}
type Query {
Donations: [Donations]
Donations: Donations
}
type Mutation {

View File

@ -57,7 +57,9 @@ describe('donations.vue', () => {
})
it('showDonations label', () => {
expect(wrapper.find('.show-donations-checkbox').text()).toBe('admin.donations.showDonationsCheckboxLabel')
expect(wrapper.find('.show-donations-checkbox').text()).toBe(
'admin.donations.showDonationsCheckboxLabel',
)
})
it('donations goal label', () => {
@ -65,7 +67,9 @@ describe('donations.vue', () => {
})
it('donations progress label', () => {
expect(wrapper.find('[data-test="donations-progress"]').text()).toBe('admin.donations.progress')
expect(wrapper.find('[data-test="donations-progress"]').text()).toBe(
'admin.donations.progress',
)
})
it('save button text', () => {
@ -94,26 +98,19 @@ describe('donations.vue', () => {
})
describe('showDonations', () => {
it.skip('set as default', () => {
})
it.skip('set as default', () => {})
it.skip('click changes value', () => {
})
it.skip('click changes value', () => {})
})
it.skip('XXX', () => {
})
it.skip('XXX', () => {})
it.skip('XXX', () => {
})
it.skip('XXX', () => {})
it.skip('XXX', () => {
})
it.skip('XXX', () => {})
it.skip('XXX', () => {
})
it.skip('XXX', () => {})
it.skip('XXX', () => {
})
it.skip('XXX', () => {})
})
})

View File

@ -57,14 +57,25 @@ export default {
methods: {
submit() {
const { showDonations } = this
const { goal, progress } = this.formData
let { goal, progress } = this.formData
goal = typeof goal === 'string' && goal.length > 0 ? goal : '15000'
progress = typeof progress === 'string' && progress.length > 0 ? progress : '0'
this.$apollo
.mutate({
mutation: UpdateDonations(),
variables: {
showDonations,
goal: parseInt(goal),
progress: parseInt(progress),
progress: parseInt(progress) < parseInt(goal) ? parseInt(progress) : parseInt(goal),
},
update: (_store, { data }) => {
if (!data || !data.UpdateDonations) return
const { showDonations, goal, progress } = data.UpdateDonations
this.showDonations = showDonations
this.formData = {
goal: goal.toString(10),
progress: progress < goal ? progress.toString(10) : goal.toString(10),
}
},
})
.then(() => {
@ -79,12 +90,12 @@ export default {
return DonationsQuery()
},
update({ Donations }) {
if (!Donations[0]) return
const { showDonations, goal, progress } = Donations[0]
if (!Donations) return
const { showDonations, goal, progress } = Donations
this.showDonations = showDonations
this.formData = {
goal,
progress,
goal: goal.toString(10),
progress: progress < goal ? progress.toString(10) : goal.toString(10),
}
},
},

View File

@ -154,11 +154,11 @@ export default {
return DonationsQuery()
},
update({ Donations }) {
if (!Donations[0]) return
const { showDonations, goal, progress } = Donations[0]
if (!Donations) return
const { showDonations, goal, progress } = Donations
this.showDonations = showDonations
this.goal = goal
this.progress = progress
this.progress = progress < goal ? progress : goal
},
},
Post: {