added user repo and group management working now
This commit is contained in:
@@ -7,6 +7,33 @@ import store from "@/store";
|
||||
const baseDomain = "http://localhost:5443";
|
||||
const API_URL = `${baseDomain}/api/v1`;
|
||||
|
||||
export default axios.create({
|
||||
const api = axios.create({
|
||||
baseURL: API_URL, headers: { Authorization: `Bearer ${store.state.access_token}` },
|
||||
});
|
||||
|
||||
api.interceptors.response.use(function (response) {
|
||||
return response;
|
||||
}, function (error) {
|
||||
if (401 === error.response.status) {
|
||||
Vue.swal({
|
||||
title: "Session Expired",
|
||||
text: "Your token/session has expired. Would you like to be redirected to the login page?",
|
||||
type: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#DD6B55",
|
||||
confirmButtonText: "Yes",
|
||||
}).then( (result) => {
|
||||
if(result.value) {
|
||||
console.log("redirect to login!");
|
||||
window.location = '/login';
|
||||
} else {
|
||||
console.log("redirect to home!");
|
||||
window.location = '/';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
export default api;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// RepositoryFactory.js
|
||||
|
||||
import GroupRepository from "./groupRepository";
|
||||
import UserRepository from "./userRepository";
|
||||
|
||||
const repositories = {
|
||||
group: GroupRepository,
|
||||
user: UserRepository,
|
||||
};
|
||||
|
||||
export const RepositoryFactory = {
|
||||
|
||||
@@ -5,7 +5,7 @@ import Repository from "./Repository";
|
||||
const resource = "/group";
|
||||
|
||||
export default {
|
||||
get() {
|
||||
getGroups() {
|
||||
return Repository.get(`${resource}`);
|
||||
},
|
||||
|
||||
|
||||
@@ -49,6 +49,14 @@ export function createUser(jwt: any, userData: any) {
|
||||
return axios.post(`${API_URL}/v1/user`, userData, { headers: { Authorization: `Bearer ${jwt}` } });
|
||||
}
|
||||
|
||||
export function fetchUserGroups(jwt: any) {
|
||||
return axios.get(`${API_URL}/v1/group`, { headers: { Authorization: `Bearer ${jwt}` } });
|
||||
}
|
||||
|
||||
export function fetchUserGroup(jwt: any, groupId: any) {
|
||||
return axios.get(`${API_URL}/v1/group/${groupId}`, { headers: { Authorization: `Bearer ${jwt}` } });
|
||||
}
|
||||
|
||||
export function fetchProfile(jwt: any) {
|
||||
Vue.$log.debug("JWT: "+ jwt);
|
||||
return axios.get(`${API_URL}/v1/user/profile`, { headers: { Authorization: `Bearer ${jwt}` } });
|
||||
|
||||
19
src/api/userRepository.js
Normal file
19
src/api/userRepository.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// groupRepository.js
|
||||
|
||||
import Repository from "./Repository";
|
||||
|
||||
const resource = "/user";
|
||||
|
||||
export default {
|
||||
getUsers() {
|
||||
return Repository.get(`${resource}`);
|
||||
},
|
||||
|
||||
getUser(userId) {
|
||||
return Repository.get(`${resource}/${userId}`);
|
||||
},
|
||||
|
||||
createUser(userData) {
|
||||
return Repository.post(`${resource}`, userData);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user