2024-09-17 22:36:40 +05:30
|
|
|
import { default as axios } from "axios";
|
|
|
|
|
|
2024-09-17 22:39:28 +05:30
|
|
|
// todo: proper typescript types for params
|
2024-09-18 22:31:48 +05:30
|
|
|
export const handleUploadCredentials = async (fileName: any, credentials: any, spreadsheetId: any, range: any): Promise<boolean> => {
|
2024-09-17 22:36:40 +05:30
|
|
|
try {
|
2024-09-18 22:31:48 +05:30
|
|
|
const response = await axios.post('http://localhost:8080/integration/upload-credentials', { fileName, credentials: JSON.parse(credentials), spreadsheetId, range });
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`Couldn't make gsheet integration for ${fileName}`);
|
|
|
|
|
}
|
2024-09-17 22:36:40 +05:30
|
|
|
} catch (error) {
|
2024-09-17 22:36:54 +05:30
|
|
|
console.error('Error uploading credentials:', error);
|
2024-09-18 22:31:48 +05:30
|
|
|
return false;
|
2024-09-17 22:36:40 +05:30
|
|
|
}
|
2024-09-19 09:14:18 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const handleWriteToGsheet = async (fileName: string, runId: string): Promise<{
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
|
|
|
|
}> => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.post(`http://localhost:8080/integration/update-google-sheet/${fileName}/${runId}`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`Couldn't make gsheet integration for ${fileName}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error uploading credentials:', error);
|
|
|
|
|
return { success: false, message: 'Failed to write to Google Sheet' };
|
|
|
|
|
}
|
2024-09-18 18:30:04 +05:30
|
|
|
};
|