refac
This commit is contained in:
@@ -77,6 +77,50 @@ export const getAutomations = async (token: string) => {
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getAutomationItems = async (
|
||||
token: string,
|
||||
query: string | null,
|
||||
status: string | null,
|
||||
page: number
|
||||
): Promise<{ items: AutomationResponse[]; total: number }> => {
|
||||
let error = null;
|
||||
|
||||
const searchParams = new URLSearchParams();
|
||||
if (query) {
|
||||
searchParams.append('query', query);
|
||||
}
|
||||
if (status && status !== 'all') {
|
||||
searchParams.append('status', status);
|
||||
}
|
||||
if (page) {
|
||||
searchParams.append('page', page.toString());
|
||||
}
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/automations/list?${searchParams.toString()}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err.detail;
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const createAutomation = async (token: string, form: AutomationForm) => {
|
||||
let error = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user