2021-05-19 07:38:18 +00:00
|
|
|
import config from 'config';
|
|
|
|
|
import { authHeader, handleResponse } from '@/_helpers';
|
|
|
|
|
|
|
|
|
|
export const folderService = {
|
|
|
|
|
create,
|
2022-06-16 14:11:38 +00:00
|
|
|
deleteFolder,
|
2021-05-19 10:20:31 +00:00
|
|
|
getAll,
|
2021-09-21 13:48:28 +00:00
|
|
|
addToFolder,
|
2022-02-28 03:15:03 +00:00
|
|
|
removeAppFromFolder,
|
2022-06-16 14:11:38 +00:00
|
|
|
updateFolder,
|
2021-05-19 07:38:18 +00:00
|
|
|
};
|
|
|
|
|
|
2025-02-25 06:52:50 +00:00
|
|
|
function getAll(searchKey = '', type = 'front-end') {
|
2023-04-06 11:12:58 +00:00
|
|
|
const requestOptions = { method: 'GET', headers: authHeader(), credentials: 'include' };
|
2025-02-25 06:52:50 +00:00
|
|
|
return fetch(`${config.apiUrl}/folder-apps?searchKey=${searchKey}&type=${type}`, requestOptions).then(handleResponse);
|
2021-05-19 07:53:01 +00:00
|
|
|
}
|
2021-05-19 07:38:18 +00:00
|
|
|
|
2025-02-25 06:52:50 +00:00
|
|
|
function create(name, type) {
|
2021-05-19 07:38:18 +00:00
|
|
|
const body = {
|
2021-09-21 13:48:28 +00:00
|
|
|
name,
|
2025-02-25 06:52:50 +00:00
|
|
|
type,
|
2021-05-19 07:38:18 +00:00
|
|
|
};
|
|
|
|
|
|
2022-02-28 03:15:03 +00:00
|
|
|
const requestOptions = {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: authHeader(),
|
2023-04-06 11:12:58 +00:00
|
|
|
credentials: 'include',
|
2022-02-28 03:15:03 +00:00
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
};
|
2021-05-19 07:38:18 +00:00
|
|
|
return fetch(`${config.apiUrl}/folders`, requestOptions).then(handleResponse);
|
|
|
|
|
}
|
2021-05-19 10:20:31 +00:00
|
|
|
|
2022-06-16 14:11:38 +00:00
|
|
|
function updateFolder(name, id) {
|
|
|
|
|
const body = {
|
|
|
|
|
name,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const requestOptions = {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
headers: authHeader(),
|
2023-04-06 11:12:58 +00:00
|
|
|
credentials: 'include',
|
2022-06-16 14:11:38 +00:00
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
};
|
|
|
|
|
return fetch(`${config.apiUrl}/folders/${id}`, requestOptions).then(handleResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteFolder(id) {
|
|
|
|
|
const requestOptions = {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
headers: authHeader(),
|
2023-04-06 11:12:58 +00:00
|
|
|
credentials: 'include',
|
2022-06-16 14:11:38 +00:00
|
|
|
};
|
|
|
|
|
return fetch(`${config.apiUrl}/folders/${id}`, requestOptions).then(handleResponse);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 10:20:31 +00:00
|
|
|
function addToFolder(appId, folderId) {
|
|
|
|
|
const body = {
|
|
|
|
|
app_id: appId,
|
2021-09-21 13:48:28 +00:00
|
|
|
folder_id: folderId,
|
2021-05-19 10:20:31 +00:00
|
|
|
};
|
|
|
|
|
|
2022-02-28 03:15:03 +00:00
|
|
|
const requestOptions = {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: authHeader(),
|
2023-04-06 11:12:58 +00:00
|
|
|
credentials: 'include',
|
2022-02-28 03:15:03 +00:00
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
};
|
2025-02-25 06:52:50 +00:00
|
|
|
return fetch(`${config.apiUrl}/folder-apps`, requestOptions).then(handleResponse);
|
2021-05-19 10:20:31 +00:00
|
|
|
}
|
2022-02-28 03:15:03 +00:00
|
|
|
|
|
|
|
|
function removeAppFromFolder(appId, folderId) {
|
|
|
|
|
const body = {
|
|
|
|
|
app_id: appId,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const requestOptions = {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
headers: authHeader(),
|
2023-04-06 11:12:58 +00:00
|
|
|
credentials: 'include',
|
2022-02-28 03:15:03 +00:00
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
};
|
2025-02-25 06:52:50 +00:00
|
|
|
return fetch(`${config.apiUrl}/folder-apps/${folderId}`, requestOptions).then(handleResponse);
|
2022-02-28 03:15:03 +00:00
|
|
|
}
|