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);
|
||||
|
|
|
|||
|
|
@ -1,43 +1,43 @@
|
|||
import { Controller, Route, Tags, Request, Response, Get } from "tsoa";
|
||||
import axios from "axios";
|
||||
// import { Controller, Route, Tags, Request, Response, Get } from "tsoa";
|
||||
// import axios from "axios";
|
||||
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
// 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");
|
||||
}
|
||||
// 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>);
|
||||
// const params = new URLSearchParams(req.query as Record<string, string>);
|
||||
|
||||
// สร้าง URL ใหม่
|
||||
const newUrl = params.toString() ? `${id}?${params.toString()}` : id;
|
||||
// // สร้าง 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}`;
|
||||
// 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 });
|
||||
// // เรียก API generate-pdf
|
||||
// const apiResponse = await axios.post(APIAPI_DASHBOARD, { url: body });
|
||||
|
||||
console.log("Response:", apiResponse.data.pdfUrl);
|
||||
// console.log("Response:", apiResponse.data.pdfUrl);
|
||||
|
||||
return apiResponse.data.pdfUrl;
|
||||
} catch (error) {}
|
||||
}
|
||||
}
|
||||
// return apiResponse.data.pdfUrl;
|
||||
// } catch (error) {}
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue