fix(bff): correctly pass all filter options to backend sync-sheets API

This commit is contained in:
2026-10-07 20:00:41 -03:00
parent be3ec3fd89
commit cb77ba57de
+23 -5
View File
@@ -83,8 +83,15 @@ const handleGoogleSheetsImport = async (req, res, justSynced = false) => {
if (justSynced) { if (justSynced) {
try { try {
const syncPayload = {}; const syncPayload = {};
if (req.body && req.body.sheets_url) { if (req.body) {
syncPayload.sheets_url = req.body.sheets_url; if (req.body.sheets_url) syncPayload.sheets_url = req.body.sheets_url;
if (req.body.filter_career) syncPayload.filter_career = req.body.filter_career.trim();
if (req.body.filter_subject) syncPayload.filter_subject = req.body.filter_subject.trim();
if (req.body.filter_day) syncPayload.filter_day = req.body.filter_day.trim();
if (req.body.manual_date) syncPayload.manual_date = req.body.manual_date.trim();
if (req.body.single_date_only === 'true' || req.body.single_date_only === true || req.body.single_date_only === 'on') {
syncPayload.single_date_only = true;
}
} }
const syncRes = await req.apiClient.post('/dashboard/sync-sheets', syncPayload, { timeout: 90000 }); const syncRes = await req.apiClient.post('/dashboard/sync-sheets', syncPayload, { timeout: 90000 });
if (syncRes.data && syncRes.data.stats) { if (syncRes.data && syncRes.data.stats) {
@@ -101,10 +108,14 @@ const handleGoogleSheetsImport = async (req, res, justSynced = false) => {
]); ]);
if (cR.status === 'fulfilled') metrics.total_classrooms = cR.value.data?.classrooms?.length || 0; if (cR.status === 'fulfilled') metrics.total_classrooms = cR.value.data?.classrooms?.length || 0;
if (rR.status === 'fulfilled') metrics.total_reservations = rR.value.data?.reservations?.length || 0; if (rR.status === 'fulfilled') metrics.total_reservations = rR.value.data?.reservations?.length || 0;
if (crR.status === 'fulfilled') metrics.total_careers = crR.value.data?.careers?.length || 0; if (crR.status === 'fulfilled') {
availableCareers = crR.value.data?.careers || [];
metrics.total_careers = availableCareers.length;
}
if (sR.status === 'fulfilled') { if (sR.status === 'fulfilled') {
metrics.total_subjects = sR.value.data?.subjects?.length || 0; availableSubjects = sR.value.data?.subjects || [];
recentSubjects = (sR.value.data?.subjects || []).slice(0, 15); metrics.total_subjects = availableSubjects.length;
recentSubjects = availableSubjects.slice(0, 15);
} }
if (cmR.status === 'fulfilled') metrics.total_commissions = cmR.value.data?.commissions?.length || 0; if (cmR.status === 'fulfilled') metrics.total_commissions = cmR.value.data?.commissions?.length || 0;
} catch (e) { } } catch (e) { }
@@ -124,6 +135,13 @@ const handleGoogleSheetsImport = async (req, res, justSynced = false) => {
sync_error: syncError, sync_error: syncError,
sheets_config: sheetsConfig, sheets_config: sheetsConfig,
recent_subjects: recentSubjects.length > 0 ? recentSubjects : MOCK_RECENT_SUBJECTS, recent_subjects: recentSubjects.length > 0 ? recentSubjects : MOCK_RECENT_SUBJECTS,
available_careers: availableCareers,
available_subjects: availableSubjects,
filter_career: req.body?.filter_career || '',
filter_subject: req.body?.filter_subject || '',
filter_day: req.body?.filter_day || '',
manual_date: req.body?.manual_date || '',
single_date_only: req.body?.single_date_only === 'true' || req.body?.single_date_only === 'on',
flash_msg: flashMsg, flash_msg: flashMsg,
flash_type: flashType flash_type: flashType
}); });