diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 35b3d160..910c7531 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -330,4 +330,27 @@ router.get('/gsheets/files', requireSignIn, async (req, res) => { console.log('Error fetching Google Sheets files:', error); res.status(500).json({ message: `Error retrieving Google Sheets files: ${error.message}` }); } -}); \ No newline at end of file +}); + +// Step 5: Update robot's google_sheet_id when a Google Sheet is selected +router.post('/gsheets/update', requireSignIn, async (req, res) => { + const { spreadsheetId, robotId } = req.body; + + if (!spreadsheetId || !robotId) { + return res.status(400).json({ message: 'Spreadsheet ID and Robot ID are required' }); + } + + try { + let robot = await Robot.findOne({ where: { 'recording_meta.id': robotId }, raw:true }); + + if (!robot) { + return res.status(404).json({ message: 'Robot not found' }); + } + + await robot.update({ google_sheet_id: spreadsheetId }); + + res.json({ message: 'Robot updated with selected Google Sheet ID' }); + } catch (error) { + res.status(500).json({ message: `Error updating robot: ${error.message}` }); + } +});