API Dashbord
This commit is contained in:
parent
5267478dce
commit
fd8728c0cb
1 changed files with 44 additions and 0 deletions
44
src/controllers/DashboardController.ts
Normal file
44
src/controllers/DashboardController.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ลบ id จาก query params
|
||||||
|
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