update api calls for User views

This commit is contained in:
axolotle 2021-02-19 18:41:41 +01:00
parent 90636231e2
commit 4658c3d712
4 changed files with 28 additions and 19 deletions

View file

@ -60,6 +60,7 @@
</template> </template>
<script> <script>
import api from '@/api'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { validationMixin } from 'vuelidate' import { validationMixin } from 'vuelidate'
@ -74,9 +75,9 @@ export default {
data () { data () {
return { return {
queries: [ queries: [
{ uri: 'users' }, ['GET', { uri: 'users' }],
{ uri: 'domains' }, ['GET', { uri: 'domains' }],
{ uri: 'domains/main', storeKey: 'main_domain' } ['GET', { uri: 'domains/main', storeKey: 'main_domain' }]
], ],
form: { form: {
@ -174,12 +175,11 @@ export default {
onSubmit () { onSubmit () {
const data = formatFormData(this.form, { flatten: true }) const data = formatFormData(this.form, { flatten: true })
this.$store.dispatch( api.post({ uri: 'users' }, data).then(() => {
'POST', { uri: 'users', data }
).then(() => {
this.$router.push({ name: 'user-list' }) this.$router.push({ name: 'user-list' })
}).catch(error => { }).catch(err => {
this.serverError = error.message if (err.name !== 'APIBadRequestError') throw err
this.serverError = err.message
}) })
} }
}, },

View file

@ -111,6 +111,7 @@
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { validationMixin } from 'vuelidate' import { validationMixin } from 'vuelidate'
import api from '@/api'
import { arrayDiff } from '@/helpers/commons' import { arrayDiff } from '@/helpers/commons'
import { sizeToM, adressToFormValue, formatFormData } from '@/helpers/yunohostArguments' import { sizeToM, adressToFormValue, formatFormData } from '@/helpers/yunohostArguments'
import { import {
@ -130,9 +131,9 @@ export default {
data () { data () {
return { return {
queries: [ queries: [
{ uri: 'users', param: this.name, storeKey: 'users_details' }, ['GET', { uri: 'users', param: this.name, storeKey: 'users_details' }],
{ uri: 'domains/main', storeKey: 'main_domain' }, ['GET', { uri: 'domains/main', storeKey: 'main_domain' }],
{ uri: 'domains' } ['GET', { uri: 'domains' }]
], ],
form: { form: {
@ -293,12 +294,14 @@ export default {
return return
} }
this.$store.dispatch('PUT', api.put(
{ uri: 'users', data, param: this.name, storeKey: 'users_details' } { uri: 'users', param: this.name, storeKey: 'users_details' },
data
).then(() => { ).then(() => {
this.$router.push({ name: 'user-info', param: { name: this.name } }) this.$router.push({ name: 'user-info', param: { name: this.name } })
}).catch(error => { }).catch(err => {
this.serverError = error.message if (err.name !== 'APIBadRequestError') throw err
this.serverError = err.message
}) })
}, },

View file

@ -79,6 +79,7 @@
</template> </template>
<script> <script>
import api from '@/api'
export default { export default {
name: 'UserInfo', name: 'UserInfo',
@ -89,7 +90,9 @@ export default {
data () { data () {
return { return {
queries: [{ uri: 'users', param: this.name, storeKey: 'users_details' }], queries: [
['GET', { uri: 'users', param: this.name, storeKey: 'users_details' }]
],
purge: false purge: false
} }
}, },
@ -103,8 +106,9 @@ export default {
methods: { methods: {
deleteUser () { deleteUser () {
const data = this.purge ? { purge: '' } : {} const data = this.purge ? { purge: '' } : {}
this.$store.dispatch('DELETE', api.delete(
{ uri: 'users', param: this.name, data, storeKey: 'users_details' } { uri: 'users', param: this.name, storeKey: 'users_details' },
data
).then(() => { ).then(() => {
this.$router.push({ name: 'user-list' }) this.$router.push({ name: 'user-list' })
}) })

View file

@ -47,7 +47,9 @@ export default {
data () { data () {
return { return {
queries: [{ uri: 'users' }], queries: [
['GET', { uri: 'users' }]
],
search: '' search: ''
} }
}, },