Merge branch 'develop'
* develop: dashboard export fix API Dashbord
This commit is contained in:
commit
9b3346d24f
2 changed files with 69 additions and 0 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 { AppDataSource } from "./database/data-source";
|
||||||
import { RegisterRoutes } from "./routes";
|
import { RegisterRoutes } from "./routes";
|
||||||
import logMiddleware from "./middlewares/logs";
|
import logMiddleware from "./middlewares/logs";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await AppDataSource.initialize();
|
await AppDataSource.initialize();
|
||||||
|
|
@ -25,6 +26,31 @@ async function main() {
|
||||||
app.use("/", express.static("static"));
|
app.use("/", express.static("static"));
|
||||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
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);
|
RegisterRoutes(app);
|
||||||
|
|
||||||
app.use(error);
|
app.use(error);
|
||||||
|
|
|
||||||
43
src/controllers/DashboardController.ts
Normal file
43
src/controllers/DashboardController.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
// import { Controller, Route, Tags, Request, Response, Get } from "tsoa";
|
||||||
|
// import axios from "axios";
|
||||||
|
|
||||||
|
// import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
|
||||||
|
// import { Request as ExpressRequest } from "express";
|
||||||
|
// @Route("api/v1/probation/dashboard")
|
||||||
|
// @Tags("dashboard")
|
||||||
|
// // @Security("bearerAuth")
|
||||||
|
// @Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "สร้าง PDF")
|
||||||
|
// export class DashboardController extends Controller {
|
||||||
|
// /**
|
||||||
|
// * API สร้าง PDF
|
||||||
|
// *
|
||||||
|
// * @summary สร้าง PDF
|
||||||
|
// *
|
||||||
|
// */
|
||||||
|
// @Get()
|
||||||
|
// public async GetLinkDashboard(@Request() req: ExpressRequest) {
|
||||||
|
// try {
|
||||||
|
// // ดึงค่า 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>);
|
||||||
|
|
||||||
|
// // สร้าง URL ใหม่
|
||||||
|
// 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}`;
|
||||||
|
|
||||||
|
// // เรียก API generate-pdf
|
||||||
|
// const apiResponse = await axios.post(APIAPI_DASHBOARD, { url: body });
|
||||||
|
|
||||||
|
// console.log("Response:", apiResponse.data.pdfUrl);
|
||||||
|
|
||||||
|
// return apiResponse.data.pdfUrl;
|
||||||
|
// } catch (error) {}
|
||||||
|
// }
|
||||||
|
// }
|
||||||
Loading…
Add table
Add a link
Reference in a new issue