diff --git a/app/.DS_Store b/app/.DS_Store deleted file mode 100644 index f0385b8..0000000 Binary files a/app/.DS_Store and /dev/null differ diff --git a/app/controllers/report.controller.js b/app/controllers/report.controller.js index 491edfa..9dfe080 100644 --- a/app/controllers/report.controller.js +++ b/app/controllers/report.controller.js @@ -29,10 +29,17 @@ const toObjectIdText = (value) => { const findTemplatePathBySite = (site) => { const safeSite = [1, 2, 3].includes(Number(site)) ? Number(site) : 1; const fileName = `pdf_templete${safeSite}.pdf`; + const cwd = process.cwd(); const candidatePaths = [ path.join(ROOT_DIR, "app", "views", "upload", fileName), path.join(ROOT_DIR, "client", "build", "upload", fileName), - path.join(ROOT_DIR, "client", "public", "upload", fileName) + path.join(ROOT_DIR, "client", "public", "upload", fileName), + path.join(cwd, "app", "views", "upload", fileName), + path.join(cwd, "client", "build", "upload", fileName), + path.join(cwd, "client", "public", "upload", fileName), + path.join("/www/wwwroot/upload", fileName), + path.join(`/www/wwwroot/worldshine${safeSite}`, "app", "views", "upload", fileName), + path.join(`/www/wwwroot/worldshine${safeSite}-tspt`, "app", "views", "upload", fileName) ]; return candidatePaths.find((candidate) => fs.existsSync(candidate)) || ""; }; @@ -307,6 +314,7 @@ exports.exportRouteReportZip = async (req, res) => { archive.finalize(); } catch (err) { + console.error("Failed to export route report zip:", err); res.status(500).send({ message: err.message || "Failed to export route reports." }); diff --git a/client/src/components/trans-routes/RoutesDashboard.js b/client/src/components/trans-routes/RoutesDashboard.js index 761f91d..1a72564 100644 --- a/client/src/components/trans-routes/RoutesDashboard.js +++ b/client/src/components/trans-routes/RoutesDashboard.js @@ -14,6 +14,17 @@ import RouteCustomerTable from "./RouteCustomerTable"; const RoutesDashboard = () => { + const getErrorMessageFromBlob = async (blobData, fallback = 'Failed to export route report.') => { + try { + if (!blobData) return fallback; + const text = await blobData.text(); + if (!text) return fallback; + const parsed = JSON.parse(text); + return parsed?.message || fallback; + } catch (_err) { + return fallback; + } + }; const HIDDEN_CUSTOMER_TYPE_FILTER_VALUES = ['transferred', 'deceased', 'discharged']; const navigate = useNavigate(); const dispatch = useDispatch(); @@ -882,7 +893,8 @@ const RoutesDashboard = () => { window.URL.revokeObjectURL(downloadUrl); } catch (error) { console.error('Failed to export route report:', error); - window.alert('Failed to export route report.'); + const message = await getErrorMessageFromBlob(error?.response?.data); + window.alert(message); } } const goToHistoryPage = () => { diff --git a/client/src/components/trans-routes/RoutesHistory.js b/client/src/components/trans-routes/RoutesHistory.js index 33ee834..ce40466 100644 --- a/client/src/components/trans-routes/RoutesHistory.js +++ b/client/src/components/trans-routes/RoutesHistory.js @@ -8,6 +8,17 @@ import DatePicker from "react-datepicker"; import { AuthService, ReportService } from "../../services"; const RoutesHistory = () => { + const getErrorMessageFromBlob = async (blobData, fallback = 'Failed to export route report.') => { + try { + if (!blobData) return fallback; + const text = await blobData.text(); + if (!text) return fallback; + const parsed = JSON.parse(text); + return parsed?.message || fallback; + } catch (_err) { + return fallback; + } + }; const navigate = useNavigate(); const dispatch = useDispatch(); const inboundRoutes = useSelector(selectHistoryInboundRoutes); @@ -47,7 +58,8 @@ const RoutesHistory = () => { window.URL.revokeObjectURL(downloadUrl); } catch (error) { console.error('Failed to export route report:', error); - window.alert('Failed to export route report.'); + const message = await getErrorMessageFromBlob(error?.response?.data); + window.alert(message); } }