2024-09-18 07:28:57 +05:30
|
|
|
import { Router } from 'express';
|
2024-09-18 18:27:38 +05:30
|
|
|
import logger from "../logger";
|
2024-09-19 17:49:15 +05:30
|
|
|
import { loadIntegrations, saveIntegrations } from '../workflow-management/integrations/gsheet';
|
2024-10-06 04:08:36 +05:30
|
|
|
import { requireSignIn } from '../middlewares/auth';
|
2024-09-17 20:38:32 +05:30
|
|
|
|
2024-09-18 18:27:38 +05:30
|
|
|
export const router = Router();
|
2024-09-17 20:38:32 +05:30
|
|
|
|
2024-10-06 04:08:36 +05:30
|
|
|
router.post('/upload-credentials', requireSignIn, async (req, res) => {
|
2024-09-19 17:43:42 +05:30
|
|
|
try {
|
2024-09-18 20:00:42 +05:30
|
|
|
const { fileName, credentials, spreadsheetId, range } = req.body;
|
|
|
|
|
if (!fileName || !credentials || !spreadsheetId || !range) {
|
2024-09-19 17:43:42 +05:30
|
|
|
return res.status(400).json({ message: 'Credentials, Spreadsheet ID, and Range are required.' });
|
2024-09-17 20:39:42 +05:30
|
|
|
}
|
2024-09-19 17:49:15 +05:30
|
|
|
// *** TEMPORARILY WE STORE CREDENTIALS HERE ***
|
2024-09-19 18:39:29 +05:30
|
|
|
let integrations = loadIntegrations(fileName);
|
2024-09-19 18:30:27 +05:30
|
|
|
integrations = { fileName, spreadsheetId, range, credentials };
|
2024-09-19 18:39:29 +05:30
|
|
|
saveIntegrations(fileName, integrations);
|
2024-09-18 22:33:01 +05:30
|
|
|
logger.log('info', 'Service account credentials saved successfully.');
|
|
|
|
|
return res.send(true);
|
2024-09-19 17:43:42 +05:30
|
|
|
} catch (error: any) {
|
|
|
|
|
logger.log('error', `Error saving credentials: ${error.message}`);
|
|
|
|
|
return res.status(500).json({ message: 'Failed to save credentials.', error: error.message });
|
|
|
|
|
}
|
2024-09-19 17:49:15 +05:30
|
|
|
});
|