mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-12 03:28:53 +00:00
83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
import config from 'config';
|
|
import { authHeader, handleResponse } from '@/_helpers';
|
|
|
|
export const folderService = {
|
|
create,
|
|
deleteFolder,
|
|
getAll,
|
|
addToFolder,
|
|
removeAppFromFolder,
|
|
updateFolder,
|
|
};
|
|
|
|
function getAll(searchKey = '', type = 'front-end') {
|
|
const requestOptions = { method: 'GET', headers: authHeader(), credentials: 'include' };
|
|
return fetch(`${config.apiUrl}/folder-apps?searchKey=${searchKey}&type=${type}`, requestOptions).then(handleResponse);
|
|
}
|
|
|
|
function create(name, type) {
|
|
const body = {
|
|
name,
|
|
type,
|
|
};
|
|
|
|
const requestOptions = {
|
|
method: 'POST',
|
|
headers: authHeader(),
|
|
credentials: 'include',
|
|
body: JSON.stringify(body),
|
|
};
|
|
return fetch(`${config.apiUrl}/folders`, requestOptions).then(handleResponse);
|
|
}
|
|
|
|
function updateFolder(name, id) {
|
|
const body = {
|
|
name,
|
|
};
|
|
|
|
const requestOptions = {
|
|
method: 'PUT',
|
|
headers: authHeader(),
|
|
credentials: 'include',
|
|
body: JSON.stringify(body),
|
|
};
|
|
return fetch(`${config.apiUrl}/folders/${id}`, requestOptions).then(handleResponse);
|
|
}
|
|
|
|
function deleteFolder(id) {
|
|
const requestOptions = {
|
|
method: 'DELETE',
|
|
headers: authHeader(),
|
|
credentials: 'include',
|
|
};
|
|
return fetch(`${config.apiUrl}/folders/${id}`, requestOptions).then(handleResponse);
|
|
}
|
|
|
|
function addToFolder(appId, folderId) {
|
|
const body = {
|
|
app_id: appId,
|
|
folder_id: folderId,
|
|
};
|
|
|
|
const requestOptions = {
|
|
method: 'POST',
|
|
headers: authHeader(),
|
|
credentials: 'include',
|
|
body: JSON.stringify(body),
|
|
};
|
|
return fetch(`${config.apiUrl}/folder-apps`, requestOptions).then(handleResponse);
|
|
}
|
|
|
|
function removeAppFromFolder(appId, folderId) {
|
|
const body = {
|
|
app_id: appId,
|
|
};
|
|
|
|
const requestOptions = {
|
|
method: 'PUT',
|
|
headers: authHeader(),
|
|
credentials: 'include',
|
|
body: JSON.stringify(body),
|
|
};
|
|
return fetch(`${config.apiUrl}/folder-apps/${folderId}`, requestOptions).then(handleResponse);
|
|
}
|