rest api update user

This commit is contained in:
ogerly 2021-06-08 16:07:01 +02:00
parent 460953847b
commit 98772bc320
4 changed files with 14 additions and 6 deletions

View File

@ -93,7 +93,7 @@ const loginAPI = {
update: { update: {
'User.first_name': data.firstName, 'User.first_name': data.firstName,
'User.last_name': data.lastName, 'User.last_name': data.lastName,
/* 'User.description': description, */ 'User.description': data.description,
}, },
} }
return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload) return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)

View File

@ -22,6 +22,9 @@ export const mutations = {
lastName: (state, lastName) => { lastName: (state, lastName) => {
state.lastName = lastName state.lastName = lastName
}, },
description: (state, description) => {
state.description = description
},
} }
export const actions = { export const actions = {
@ -32,6 +35,7 @@ export const actions = {
commit('username', data.user.username) commit('username', data.user.username)
commit('firstName', data.user.first_name) commit('firstName', data.user.first_name)
commit('lastName', data.user.last_name) commit('lastName', data.user.last_name)
commit('description', data.user.description)
}, },
logout: ({ commit, state }) => { logout: ({ commit, state }) => {
commit('sessionId', null) commit('sessionId', null)
@ -39,6 +43,7 @@ export const actions = {
commit('username', '') commit('username', '')
commit('firstName', '') commit('firstName', '')
commit('lastName', '') commit('lastName', '')
commit('description', '')
sessionStorage.clear() sessionStorage.clear()
}, },
} }
@ -57,6 +62,7 @@ export const store = new Vuex.Store({
firstName: '', firstName: '',
lastName: '', lastName: '',
username: '', username: '',
description: '',
}, },
getters: {}, getters: {},
// Syncronous mutation of the state // Syncronous mutation of the state

View File

@ -40,7 +40,7 @@ describe('Vuex store', () => {
{ commit, state }, { commit, state },
{ sessionId: 1234, user: { email: 'someone@there.is', language: 'en' } }, { sessionId: 1234, user: { email: 'someone@there.is', language: 'en' } },
) )
expect(commit).toHaveBeenCalledTimes(6) expect(commit).toHaveBeenCalledTimes(7)
}) })
it('commits sessionId', () => { it('commits sessionId', () => {
@ -74,7 +74,7 @@ describe('Vuex store', () => {
it('calls two commits', () => { it('calls two commits', () => {
logout({ commit, state }) logout({ commit, state })
expect(commit).toHaveBeenCalledTimes(5) expect(commit).toHaveBeenCalledTimes(6)
}) })
it('commits sessionId', () => { it('commits sessionId', () => {

View File

@ -52,10 +52,10 @@
<small>{{ $t('form.description') }}</small> <small>{{ $t('form.description') }}</small>
</b-col> </b-col>
<b-col v-if="editUserdata" class="col-md-9 col-sm-10"> <b-col v-if="editUserdata" class="col-md-9 col-sm-10">
{{ UserProfileTestData.desc }} {{ form.description }}
</b-col> </b-col>
<b-col v-else class="col-md-9 col-sm-10"> <b-col v-else class="col-md-9 col-sm-10">
<b-textarea rows="3" max-rows="6" v-model="form.desc"></b-textarea> <b-textarea rows="3" max-rows="6" v-model="form.description"></b-textarea>
</b-col> </b-col>
</b-row> </b-row>
</div> </div>
@ -78,7 +78,7 @@ export default {
form: { form: {
firstName: this.$store.state.firstName, firstName: this.$store.state.firstName,
lastName: this.$store.state.lastName, lastName: this.$store.state.lastName,
desc: this.UserProfileTestData.desc, description: this.$store.state.description,
}, },
} }
}, },
@ -90,11 +90,13 @@ export default {
{ {
firstName: this.form.firstName, firstName: this.form.firstName,
lastName: this.form.lastName, lastName: this.form.lastName,
description: this.form.description,
}, },
) )
if (result.success) { if (result.success) {
this.$store.commit('firstName', this.form.firstName) this.$store.commit('firstName', this.form.firstName)
this.$store.commit('lastName', this.form.lastName) this.$store.commit('lastName', this.form.lastName)
this.$store.commit('description', this.form.description)
this.editUserdata = true this.editUserdata = true
} else { } else {
alert(result.result.message) alert(result.result.message)