diff --git a/map/app/server.js b/map/app/server.js index 9485b5e..23dffe4 100644 --- a/map/app/server.js +++ b/map/app/server.js @@ -765,15 +765,15 @@ app.get('/api/admin/walk-sheet-config', requireAdmin, async (req, res) => { ) || response.data.list[0]; // Fallback to most recent if none have walk sheet data const walkSheetConfig = { - walk_sheet_title: settingsRow.walk_sheet_title || defaultConfig.walk_sheet_title, - walk_sheet_subtitle: settingsRow.walk_sheet_subtitle || defaultConfig.walk_sheet_subtitle, - walk_sheet_footer: settingsRow.walk_sheet_footer || defaultConfig.walk_sheet_footer, - qr_code_1_url: settingsRow.qr_code_1_url || defaultConfig.qr_code_1_url, - qr_code_1_label: settingsRow.qr_code_1_label || defaultConfig.qr_code_1_label, - qr_code_2_url: settingsRow.qr_code_2_url || defaultConfig.qr_code_2_url, - qr_code_2_label: settingsRow.qr_code_2_label || defaultConfig.qr_code_2_label, - qr_code_3_url: settingsRow.qr_code_3_url || defaultConfig.qr_code_3_url, - qr_code_3_label: settingsRow.qr_code_3_label || defaultConfig.qr_code_3_label + walk_sheet_title: settingsRow.walk_sheet_title || settingsRow['Walk Sheet Title'] || defaultConfig.walk_sheet_title, + walk_sheet_subtitle: settingsRow.walk_sheet_subtitle || settingsRow['Walk Sheet Subtitle'] || defaultConfig.walk_sheet_subtitle, + walk_sheet_footer: settingsRow.walk_sheet_footer || settingsRow['Walk Sheet Footer'] || defaultConfig.walk_sheet_footer, + qr_code_1_url: settingsRow.qr_code_1_url || settingsRow['QR Code 1 URL'] || defaultConfig.qr_code_1_url, + qr_code_1_label: settingsRow.qr_code_1_label || settingsRow['QR Code 1 Label'] || defaultConfig.qr_code_1_label, + qr_code_2_url: settingsRow.qr_code_2_url || settingsRow['QR Code 2 URL'] || defaultConfig.qr_code_2_url, + qr_code_2_label: settingsRow.qr_code_2_label || settingsRow['QR Code 2 Label'] || defaultConfig.qr_code_2_label, + qr_code_3_url: settingsRow.qr_code_3_url || settingsRow['QR Code 3 URL'] || defaultConfig.qr_code_3_url, + qr_code_3_label: settingsRow.qr_code_3_label || settingsRow['QR Code 3 Label'] || defaultConfig.qr_code_3_label }; logger.info(`Retrieved walk sheet config from database (ID: ${settingsRow.Id || settingsRow.id})`); @@ -842,18 +842,31 @@ app.post('/api/admin/walk-sheet-config', requireAdmin, async (req, res) => { created_at: timestamp, created_by: userEmail, - // Walk sheet fields with validation + // Walk sheet fields in underscore format walk_sheet_title: (config.walk_sheet_title || '').toString().trim(), walk_sheet_subtitle: (config.walk_sheet_subtitle || '').toString().trim(), walk_sheet_footer: (config.walk_sheet_footer || '').toString().trim(), - // QR Code fields with URL validation + // Also save in title case format for compatibility + 'Walk Sheet Title': (config.walk_sheet_title || '').toString().trim(), + 'Walk Sheet Subtitle': (config.walk_sheet_subtitle || '').toString().trim(), + 'Walk Sheet Footer': (config.walk_sheet_footer || '').toString().trim(), + + // QR Code fields in underscore format qr_code_1_url: validateUrl(config.qr_code_1_url), qr_code_1_label: (config.qr_code_1_label || '').toString().trim(), qr_code_2_url: validateUrl(config.qr_code_2_url), qr_code_2_label: (config.qr_code_2_label || '').toString().trim(), qr_code_3_url: validateUrl(config.qr_code_3_url), - qr_code_3_label: (config.qr_code_3_label || '').toString().trim() + qr_code_3_label: (config.qr_code_3_label || '').toString().trim(), + + // Also save in title case format + 'QR Code 1 URL': validateUrl(config.qr_code_1_url), + 'QR Code 1 Label': (config.qr_code_1_label || '').toString().trim(), + 'QR Code 2 URL': validateUrl(config.qr_code_2_url), + 'QR Code 2 Label': (config.qr_code_2_label || '').toString().trim(), + 'QR Code 3 URL': validateUrl(config.qr_code_3_url), + 'QR Code 3 Label': (config.qr_code_3_label || '').toString().trim() }; logger.info('Prepared walk sheet data for saving:', JSON.stringify(walkSheetData, null, 2)); @@ -1750,6 +1763,41 @@ app.post('/api/debug/test-walk-sheet-save', requireAdmin, async (req, res) => { } }); +// Debug endpoint to see raw walk sheet data +app.get('/api/debug/walk-sheet-raw', requireAdmin, async (req, res) => { + try { + if (!SETTINGS_SHEET_ID) { + return res.json({ error: 'No settings sheet ID configured' }); + } + + const response = await axios.get( + `${process.env.NOCODB_API_URL}/db/data/v1/${process.env.NOCODB_PROJECT_ID}/${SETTINGS_SHEET_ID}`, + { + headers: { + 'xc-token': process.env.NOCODB_API_TOKEN + }, + params: { + sort: '-created_at', + limit: 5 + } + } + ); + + return res.json({ + success: true, + tableId: SETTINGS_SHEET_ID, + records: response.data?.list || [], + count: response.data?.list?.length || 0 + }); + } catch (error) { + logger.error('Error fetching raw walk sheet data:', error); + return res.status(500).json({ + success: false, + error: error.message + }); + } +}); + // Error handling middleware app.use((err, req, res, next) => { logger.error('Unhandled error:', err);