dashboard export
This commit is contained in:
parent
4ba3778d27
commit
b6834294e2
2 changed files with 61 additions and 35 deletions
26
src/app.ts
26
src/app.ts
|
|
@ -8,6 +8,7 @@ import error from "./middlewares/error";
|
|||
import { AppDataSource } from "./database/data-source";
|
||||
import { RegisterRoutes } from "./routes";
|
||||
import logMiddleware from "./middlewares/logs";
|
||||
import axios from "axios";
|
||||
|
||||
async function main() {
|
||||
await AppDataSource.initialize();
|
||||
|
|
@ -25,6 +26,31 @@ async function main() {
|
|||
app.use("/", express.static("static"));
|
||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||
|
||||
app.get("/api/v1/probation/dashboard", async (req, res) => {
|
||||
// ดึงค่า id จาก query params
|
||||
const id = req.query.id as string;
|
||||
if (!id) {
|
||||
throw new Error("Missing 'id' parameter");
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(req.query as Record<string, string>);
|
||||
const newUrl = params.toString() ? `${id}?${params.toString()}` : id;
|
||||
|
||||
const APIAPI_DASHBOARD = `${process.env.API_DASHBOARD}/generate-pdf`;
|
||||
const body = `${process.env.API_DASHBOARD}/d/${newUrl}`;
|
||||
|
||||
try {
|
||||
// เรียก API generate-pdf
|
||||
const apiResponse = await axios.post(APIAPI_DASHBOARD, { url: body });
|
||||
|
||||
// console.log("Response:", apiResponse.data.pdfUrl);
|
||||
|
||||
res.redirect(apiResponse.data.pdfUrl);
|
||||
} catch (error) {
|
||||
throw new Error("Failed to generate PDF: " + error);
|
||||
}
|
||||
});
|
||||
|
||||
RegisterRoutes(app);
|
||||
|
||||
app.use(error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue