Add centralized API client with axios interceptors, remove vue-axios
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import apiClient from '@/api/client.js';
|
||||
import apiError from '@/module/apiError';
|
||||
import piniaLoginStore from '@/stores/login';
|
||||
import { JUST_CREATE_ACCOUNT_HOT_DURATION_MINS } from '@/constants/constants';
|
||||
@@ -87,7 +88,7 @@ export default defineStore('acctMgmtStore', {
|
||||
async getAllUserAccounts() {
|
||||
const apiGetUserList = `/api/users`;
|
||||
try {
|
||||
const response = await this.$axios.get(apiGetUserList);
|
||||
const response = await apiClient.get(apiGetUserList);
|
||||
const customizedResponseData = await this.customizeAllUserList(response.data);
|
||||
this.allUserAccoutList = await this.moveCurrentLoginUserToFirstRow(customizedResponseData);
|
||||
} catch (error) {
|
||||
@@ -135,7 +136,7 @@ export default defineStore('acctMgmtStore', {
|
||||
const apiCreateAccount = `/api/users`;
|
||||
|
||||
try {
|
||||
const response = await this.$axios.post(apiCreateAccount, userToCreate);
|
||||
const response = await apiClient.post(apiCreateAccount, userToCreate);
|
||||
if (response.status === 200) {
|
||||
this.isOneAccountJustCreate = true;
|
||||
this.justCreateUsername = userToCreate.username;
|
||||
@@ -154,7 +155,7 @@ export default defineStore('acctMgmtStore', {
|
||||
const apiDelete = `/api/users/${userToDelete}`;
|
||||
|
||||
try {
|
||||
const response = await this.$axios.delete(apiDelete);
|
||||
const response = await apiClient.delete(apiDelete);
|
||||
return response.status === 200;
|
||||
} catch (error) {
|
||||
apiError(error, 'Failed to delete the account.');
|
||||
@@ -170,7 +171,7 @@ export default defineStore('acctMgmtStore', {
|
||||
const apiEdit = `/api/users/${userToEdit}`;
|
||||
|
||||
try {
|
||||
const response = await this.$axios.put(apiEdit, {
|
||||
const response = await apiClient.put(apiEdit, {
|
||||
username: editDetail.newUsername ? editDetail.newUsername : editDetail.username,
|
||||
password: editDetail.password,
|
||||
name: editDetail.name,
|
||||
@@ -186,7 +187,7 @@ export default defineStore('acctMgmtStore', {
|
||||
const apiEdit = `/api/users/${userToEdit}`;
|
||||
|
||||
try {
|
||||
const response = await this.$axios.put(apiEdit, {
|
||||
const response = await apiClient.put(apiEdit, {
|
||||
username: userToEdit,
|
||||
name: newName,
|
||||
is_active: this.currentViewingUser.is_active,
|
||||
@@ -202,7 +203,7 @@ export default defineStore('acctMgmtStore', {
|
||||
const apiEdit = `/api/users/${userToEdit}`;
|
||||
|
||||
try {
|
||||
const response = await this.$axios.put(apiEdit, {
|
||||
const response = await apiClient.put(apiEdit, {
|
||||
username: userToEdit,
|
||||
name: this.currentViewingUser.name,
|
||||
password: newPwd,
|
||||
@@ -223,7 +224,7 @@ export default defineStore('acctMgmtStore', {
|
||||
const apiAddRole = `/api/users/${usernameToEdit}/roles/${roleCode}`;
|
||||
|
||||
try {
|
||||
const response = await this.$axios.put(apiAddRole);
|
||||
const response = await apiClient.put(apiAddRole);
|
||||
return response.status === 200;
|
||||
} catch (error) {
|
||||
apiError(error, 'Failed to add role to the account.');
|
||||
@@ -238,7 +239,7 @@ export default defineStore('acctMgmtStore', {
|
||||
const apiDeleteRole = `/api/users/${usernameToEdit}/roles/${roleCode}`;
|
||||
|
||||
try {
|
||||
const response = await this.$axios.delete(apiDeleteRole);
|
||||
const response = await apiClient.delete(apiDeleteRole);
|
||||
return response.status === 200;
|
||||
} catch (error) {
|
||||
apiError(error, 'Failed to delete a role frome the account.');
|
||||
@@ -252,7 +253,7 @@ export default defineStore('acctMgmtStore', {
|
||||
async getUserDetail(uniqueUsername: string): Promise<boolean> {
|
||||
const apiUserDetail = `/api/users/${uniqueUsername}`;
|
||||
try {
|
||||
const response = await this.$axios.get(apiUserDetail);
|
||||
const response = await apiClient.get(apiUserDetail);
|
||||
this.currentViewingUser = response.data;
|
||||
this.currentViewingUser.is_admin = response.data.roles.some(role => role.code === 'admin');
|
||||
return response.status === 200;
|
||||
|
||||
Reference in New Issue
Block a user