Files
parcer/src/api/workflow.ts

79 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-07-31 22:46:38 +05:30
import { WhereWhatPair, WorkflowFile } from "maxun-core";
2024-06-09 01:08:04 +05:30
import { emptyWorkflow } from "../shared/constants";
2024-10-24 22:24:29 +05:30
import { default as axios, AxiosResponse } from "axios";
2024-11-01 08:25:14 +05:30
import { apiUrl } from "../apiConfig";
2024-06-09 01:08:04 +05:30
export const getActiveWorkflow = async(id: string) : Promise<WorkflowFile> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/workflow/${id}`)
2024-06-09 01:08:04 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error('Something went wrong when fetching a recorded workflow');
}
} catch(error: any) {
console.log(error);
return emptyWorkflow;
}
};
2024-06-09 01:08:34 +05:30
export const getParamsOfActiveWorkflow = async(id: string) : Promise<string[]|null> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/workflow/params/${id}`)
2024-06-09 01:08:34 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error('Something went wrong when fetching the parameters of the recorded workflow');
}
} catch(error: any) {
console.log(error);
return null;
}
};
2024-06-09 01:08:55 +05:30
export const deletePair = async(index: number): Promise<WorkflowFile> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.delete(`${apiUrl}/workflow/pair/${index}`);
2024-06-09 01:08:55 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error('Something went wrong when fetching an updated workflow');
}
} catch (error: any) {
console.log(error);
return emptyWorkflow;
}
};
2024-06-09 01:09:10 +05:30
export const AddPair = async(index: number, pair: WhereWhatPair): Promise<WorkflowFile> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.post(`${apiUrl}/workflow/pair/${index}`, {
2024-06-09 01:09:10 +05:30
pair,
}, {headers: {'Content-Type': 'application/json'}});
if (response.status === 200) {
return response.data;
} else {
throw new Error('Something went wrong when fetching an updated workflow');
}
} catch (error: any) {
console.log(error);
return emptyWorkflow;
}
};
2024-06-09 01:09:21 +05:30
export const UpdatePair = async(index: number, pair: WhereWhatPair): Promise<WorkflowFile> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.put(`${apiUrl}/workflow/pair/${index}`, {
2024-06-09 01:09:21 +05:30
pair,
}, {headers: {'Content-Type': 'application/json'}});
if (response.status === 200) {
return response.data;
} else {
throw new Error('Something went wrong when fetching an updated workflow');
}
} catch (error: any) {
console.log(error);
return emptyWorkflow;
}
};