add mutation and query for automatic creations, create, list, delete

This commit is contained in:
ogerly 2022-06-06 12:39:45 +02:00
parent 92acf44c7d
commit ac88b08785
6 changed files with 108 additions and 12 deletions

View File

@ -43,7 +43,7 @@
<!-- Desc --> <!-- Desc -->
<b-form-group id="input-group-2" label="Nachricht:"> <b-form-group id="input-group-2" label="Nachricht:">
<b-form-textarea <b-form-textarea
v-model="form.text" v-model="form.memo"
size="lg" size="lg"
placeholder="Memo" placeholder="Memo"
required required
@ -106,6 +106,7 @@
</div> </div>
</template> </template>
<script> <script>
import { createAutomaticCreation } from '@/graphql/createAutomaticCreation.js'
export default { export default {
name: 'AutomaticCreationForm', name: 'AutomaticCreationForm',
props: { props: {
@ -120,7 +121,7 @@ export default {
return { return {
form: { form: {
name: null, name: null,
text: null, memo: null,
amount: null, amount: null,
startDate: null, startDate: null,
endDate: null, endDate: null,
@ -152,11 +153,32 @@ export default {
if (this.form.startDate === null) return this.toastError('No start Date') if (this.form.startDate === null) return this.toastError('No start Date')
if (this.form.endDate === null) return this.toastError('No end Date') if (this.form.endDate === null) return this.toastError('No end Date')
alert(JSON.stringify(this.form)) alert(JSON.stringify(this.form))
this.$apollo
.mutate({
mutation: createAutomaticCreation,
variables: {
startDate: this.form.startDate,
endDate: this.form.endDate,
name: this.form.name,
amount: this.form.amount,
memo: this.form.memo,
cycle: this.form.cycle,
repetition: this.form.repetition,
maxAmount: this.form.maxAmount,
},
})
.then((result) => {
this.link = result.data.createAutomaticCreation.link
this.toastSuccess(this.link)
})
.catch((error) => {
this.toastError(error.message)
})
}, },
onReset(event) { onReset(event) {
event.preventDefault() event.preventDefault()
this.form.name = null this.form.name = null
this.form.text = null this.form.memo = null
this.form.amount = null this.form.amount = null
this.form.startDate = null this.form.startDate = null
this.form.endDate = null this.form.endDate = null

View File

@ -0,0 +1,27 @@
import gql from 'graphql-tag'
export const createAutomaticCreation = gql`
mutation (
$startDate: String!
$endDate: String!
$name: String!
$amount: Decimal!
$memo: String!
$cycle: String
$repetition: String
$maxAmount: Decimal
) {
createAutomaticCreation(
startDate: $startDate
endDate: $endDate
name: $name
amount: $amount
memo: $memo
cycle: $cycle
repetition: $repetition
maxAmount: $maxAmount
) {
link
}
}
`

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const deleteAutomaticCreation = gql`
mutation ($id: Int!) {
deleteAutomaticCreation(id: $id)
}
`

View File

@ -0,0 +1,18 @@
import gql from 'graphql-tag'
export const listAutomaticCreations = gql`
query {
listAutomaticCreations {
id
startDate
endDate
name
memo
amount
cycle
repetition
maxAmount
link
}
}
`

View File

@ -0,0 +1,18 @@
import gql from 'graphql-tag'
export const showAutomaticCreation = gql`
query ($id: Int!) {
showAutomaticCreation {
id
startDate
endDate
name
memo
amount
cycle
repetition
maxAmount
code
}
}
`

View File

@ -33,6 +33,7 @@
</template> </template>
<script> <script>
import { getPendingCreations } from '../graphql/getPendingCreations' import { getPendingCreations } from '../graphql/getPendingCreations'
import { listAutomaticCreations } from '@/graphql/listAutomaticCreations.js'
import AutomaticCreation from '../components/AutomaticCreation.vue' import AutomaticCreation from '../components/AutomaticCreation.vue'
export default { export default {
@ -57,15 +58,18 @@ export default {
}) })
}, },
async getAutomaticCreations() { async getAutomaticCreations() {
// TODO this.$apollo
// this.$apollo .query({
// .query({ query: listAutomaticCreations,
// query: getAutomaticCreations, fetchPolicy: 'network-only',
// fetchPolicy: 'network-only', })
// }) .then((result) => {
// .then((result) => { this.toastSuccess('TODO! change this.items')
// })
// }) .catch(() => {
this.toastError('listAutomaticCreations has no result, use default data')
})
this.items = [ this.items = [
{ {
id: 1, id: 1,