Implemented creation and updating of users.

This commit is contained in:
Sockenklaus
2021-11-03 00:36:41 +01:00
parent a9b394bf09
commit cfcfeba170
3 changed files with 131 additions and 47 deletions

View File

@@ -99,13 +99,40 @@ export const useEmployee = defineStore({
/** TODO: #23 Persist user if password is changed */
async persist() {
try {
const result = await axios.patch('employees/'+this.employee.id, this.employee,
{
headers: {
'Authorization': 'Bearer '+user.token
let result
if(isNaN(this.user.id) && this.user.username.length > 0){
result = await axios.post(
'users',
{
username: this.user.username,
password: this.user.password
},
{
headers: user.header
}
)
}
else if (this.user.password.length > 0 && this.user.password === this.user.passwordConfirm){
result = await axios.patch(
'users/'+this.user.id,
{
password: this.user.password
},
{
headers: user.header
}
)
}
result = await axios.patch(
'employees/'+this.employee.id,
this.employee,
{
headers: user.header
}
)
Object.assign(this.clean.employee, this.employee)
Object.assign(this.clean.user, this.user)
notifications.add('success', result.statusText)
@@ -115,6 +142,10 @@ export const useEmployee = defineStore({
else console.log(error)
}
}
},
getters: {
}
})