Implemented creation and updating of users.
This commit is contained in:
@@ -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: {
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user