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

View file

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

View file

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

View file

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