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
|
|
|
|
2025-01-01 23:31:37 +05:30
|
|
|
export const getActiveWorkflow = async (id: string): Promise<WorkflowFile> => {
|
2024-06-09 01:08:04 +05:30
|
|
|
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');
|
|
|
|
|
}
|
2025-01-01 23:31:37 +05:30
|
|
|
} catch (error: any) {
|
2024-06-09 01:08:04 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return emptyWorkflow;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-01 23:31:37 +05:30
|
|
|
export const getParamsOfActiveWorkflow = async (id: string): Promise<string[] | null> => {
|
2024-06-09 01:08:34 +05:30
|
|
|
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');
|
|
|
|
|
}
|
2025-01-01 23:31:37 +05:30
|
|
|
} catch (error: any) {
|
2024-06-09 01:08:34 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-01 23:31:37 +05:30
|
|
|
export const deletePair = async (index: number): Promise<WorkflowFile> => {
|
2024-06-09 01:08:55 +05:30
|
|
|
try {
|
2025-01-01 23:31:37 +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;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-01 23:31:37 +05:30
|
|
|
export const AddPair = async (index: number, pair: WhereWhatPair): Promise<WorkflowFile> => {
|
2024-06-09 01:09:10 +05:30
|
|
|
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,
|
2025-01-01 23:31:37 +05:30
|
|
|
}, { headers: { 'Content-Type': 'application/json' } });
|
2024-06-09 01:09:10 +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;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-01 23:31:37 +05:30
|
|
|
export const UpdatePair = async (index: number, pair: WhereWhatPair): Promise<WorkflowFile> => {
|
2024-06-09 01:09:21 +05:30
|
|
|
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,
|
2025-01-01 23:31:37 +05:30
|
|
|
}, { headers: { 'Content-Type': 'application/json' } });
|
2024-06-09 01:09:21 +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;
|
|
|
|
|
}
|
|
|
|
|
};
|