feature: admin role edit API

This commit is contained in:
Cindy Chang
2024-06-27 14:21:27 +08:00
parent 65fdb2a945
commit 9b2bab9124
3 changed files with 62 additions and 7 deletions

View File

@@ -147,6 +147,42 @@ export default defineStore('acctMgmtStore', {
return false;
};
},
/** Add a role to the user in database.
* @param {string} usernameToEdit
* @param {string} roleCode
*/
async addRoleToUser(usernameToEdit, roleCode) {
const apiAddRole = `/api/users/${usernameToEdit}/roles/${roleCode}`;
try{
const response = await this.$axios.put(apiAddRole);
if(response.status === 200) {
return true;
}
}
catch(error) {
apiError(error, 'Failed to add role to the account.');
return false;
};
},
/** Delete a role from the user in database.
* @param {string} usernameToEdit
* @param {string} roleCode
*/
async deleteRoleToUser(usernameToEdit, roleCode) {
const apiDeleteRole = `/api/users/${usernameToEdit}/roles/${roleCode}`;
try{
const response = await this.$axios.delete(apiDeleteRole);
if(response.status === 200) {
return true;
}
}
catch(error) {
apiError(error, 'Failed to delete a role frome the account.');
return false;
};
},
/**
* Get user detail by unique username.
* @param {string} uniqueUsername