Move API_ORIGIN into constants.js
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
|
||||
import { fetcher } from 'pankow';
|
||||
import { API_ORIGIN } from '../constants.js';
|
||||
|
||||
function create() {
|
||||
const accessToken = localStorage.token;
|
||||
const origin = import.meta.env.VITE_API_ORIGIN || window.location.origin;
|
||||
|
||||
return {
|
||||
async list() {
|
||||
let result;
|
||||
try {
|
||||
result = await fetcher.get(`${origin}/api/v1/groups`, { access_token: accessToken });
|
||||
result = await fetcher.get(`${API_ORIGIN}/api/v1/groups`, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
@@ -20,7 +20,7 @@ function create() {
|
||||
async add(name, userIds, appIds) {
|
||||
let result;
|
||||
try {
|
||||
result = await fetcher.post(`${origin}/api/v1/groups`, { name }, { access_token: accessToken });
|
||||
result = await fetcher.post(`${API_ORIGIN}/api/v1/groups`, { name }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
@@ -30,7 +30,7 @@ function create() {
|
||||
if (userIds.length) {
|
||||
let resultUserIds;
|
||||
try {
|
||||
resultUserIds = await fetcher.put(`${origin}/api/v1/groups/${result.body.id}/members`, { userIds }, { access_token: accessToken });
|
||||
resultUserIds = await fetcher.put(`${API_ORIGIN}/api/v1/groups/${result.body.id}/members`, { userIds }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
@@ -41,7 +41,7 @@ function create() {
|
||||
if (appIds.length) {
|
||||
let resultAppIds;
|
||||
try {
|
||||
resultAppIds = await fetcher.put(`${origin}/api/v1/groups/${result.body.id}/apps`, { appIds }, { access_token: accessToken });
|
||||
resultAppIds = await fetcher.put(`${API_ORIGIN}/api/v1/groups/${result.body.id}/apps`, { appIds }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
@@ -54,7 +54,7 @@ function create() {
|
||||
async update(id, name, userIds, appIds) {
|
||||
let result;
|
||||
try {
|
||||
result = await fetcher.put(`${origin}/api/v1/groups/${id}/name`, { name }, { access_token: accessToken });
|
||||
result = await fetcher.put(`${API_ORIGIN}/api/v1/groups/${id}/name`, { name }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
@@ -62,7 +62,7 @@ function create() {
|
||||
if (result.status !== 200) return [result];
|
||||
|
||||
try {
|
||||
result = await fetcher.put(`${origin}/api/v1/groups/${id}/members`, { userIds }, { access_token: accessToken });
|
||||
result = await fetcher.put(`${API_ORIGIN}/api/v1/groups/${id}/members`, { userIds }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
@@ -70,7 +70,7 @@ function create() {
|
||||
if (result.status !== 200) return [result];
|
||||
|
||||
try {
|
||||
result = await fetcher.put(`${origin}/api/v1/groups/${id}/apps`, { appIds }, { access_token: accessToken });
|
||||
result = await fetcher.put(`${API_ORIGIN}/api/v1/groups/${id}/apps`, { appIds }, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
@@ -82,7 +82,7 @@ function create() {
|
||||
async remove(id) {
|
||||
let result;
|
||||
try {
|
||||
result = await fetcher.del(`${origin}/api/v1/groups/${id}`, { access_token: accessToken });
|
||||
result = await fetcher.del(`${API_ORIGIN}/api/v1/groups/${id}`, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user