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 -->
<b-form-group id="input-group-2" label="Nachricht:">
<b-form-textarea
v-model="form.text"
v-model="form.memo"
size="lg"
placeholder="Memo"
required
@ -106,6 +106,7 @@
</div>
</template>
<script>
import { createAutomaticCreation } from '@/graphql/createAutomaticCreation.js'
export default {
name: 'AutomaticCreationForm',
props: {
@ -120,7 +121,7 @@ export default {
return {
form: {
name: null,
text: null,
memo: null,
amount: null,
startDate: null,
endDate: null,
@ -152,11 +153,32 @@ export default {
if (this.form.startDate === null) return this.toastError('No start Date')
if (this.form.endDate === null) return this.toastError('No end Date')
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) {
event.preventDefault()
this.form.name = null
this.form.text = null
this.form.memo = null
this.form.amount = null
this.form.startDate = 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>
<script>
import { getPendingCreations } from '../graphql/getPendingCreations'
import { listAutomaticCreations } from '@/graphql/listAutomaticCreations.js'
import AutomaticCreation from '../components/AutomaticCreation.vue'
export default {
@ -57,15 +58,18 @@ export default {
})
},
async getAutomaticCreations() {
// TODO
// this.$apollo
// .query({
// query: getAutomaticCreations,
// fetchPolicy: 'network-only',
// })
// .then((result) => {
//
// })
this.$apollo
.query({
query: listAutomaticCreations,
fetchPolicy: 'network-only',
})
.then((result) => {
this.toastSuccess('TODO! change this.items')
})
.catch(() => {
this.toastError('listAutomaticCreations has no result, use default data')
})
this.items = [
{
id: 1,