persist installed. MyAccount in progress

This commit is contained in:
Cindy Chang
2024-08-29 14:19:27 +08:00
parent 495fcf7b03
commit 1883818b8b
6 changed files with 184 additions and 20 deletions

View File

@@ -25,6 +25,7 @@ interface EditDetail {
}
export default defineStore('acctMgmtStore', {
persist: true,
state: () => ({
allUserAccoutList: [] as User[],
isAcctMenuOpen: false,
@@ -181,6 +182,37 @@ export default defineStore('acctMgmtStore', {
return false;
}
},
async editAccountName(userToEdit: string, newName: string): Promise<boolean> {
const apiEdit = `/api/users/${userToEdit}`;
try {
const response = await this.$axios.put(apiEdit, {
username: userToEdit,
name: newName,
is_active: this.currentViewingUser.is_active,
});
return response.status === 200;
} catch (error) {
apiError(error, 'Failed to edit name of account.');
return false;
}
},
async editAccountPwd(userToEdit: string, newPwd: string): Promise<boolean> {
const apiEdit = `/api/users/${userToEdit}`;
try {
const response = await this.$axios.put(apiEdit, {
username: userToEdit,
name: this.currentViewingUser.name,
password: newPwd,
is_active: this.currentViewingUser.is_active,
});
return response.status === 200;
} catch (error) {
apiError(error, 'Failed to edit password of account.');
return false;
}
},
/** Add a role to the user in database.
* @param {string} usernameToEdit
* @param {string} roleCode