import { Controller, Request, Get, Post, Put, Delete, Patch, Route, Security, Tags, Path, } from "tsoa"; import axios from "axios"; import HttpError from "./http-error"; import { CreateProfileSalary, ProfileSalary } from "../entities/ProfileSalary"; import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { RequestWithUser } from "../middlewares/user"; import HttpStatus from "./http-status"; import HttpSuccess from "./http-success"; import permission from "./permission"; import { AppDataSource } from "../database/data-source"; import { Profile } from "../entities/Profile"; class CallAPI { private profileRepo = AppDataSource.getRepository(Profile); private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); //Get public async GetData(request: any, @Path() path: any) { const token = "Bearer " + request.headers.authorization.replace("Bearer ", ""); const url = process.env.API_URL + path; try { const response = await axios.get(url, { headers: { Authorization: `${token}`.includes("Bearer "), "Content-Type": "application/json", api_key: process.env.API_KEY, }, }); return response.data.result; } catch (error) { throw error; } } //Get (response.data) public async GetData2(request: any, @Path() path: any) { const token = "Bearer " + request.headers.authorization.replace("Bearer ", ""); const url = process.env.API_URL + path; try { const response = await axios.get(url, { headers: { Authorization: `${token}`.includes("Bearer "), "Content-Type": "application/json", api_key: process.env.API_KEY, }, }); return response.data; } catch (error) { throw error; } } //Post public async PostData(request: any, @Path() path: any, sendData: any) { const token = "Bearer " + request.headers.authorization.replace("Bearer ", ""); const url = process.env.API_URL + path; try { const response = await axios.post(url, sendData, { headers: { Authorization: `${token}`, "Content-Type": "application/json", api_key: process.env.API_KEY, }, }); return response.data.result; } catch (error) { console.log(error); throw error; } } //Post public async PostDataKeycloak(@Path() path: any, sendData: any) { // const token = request.headers.authorization; const url = process.env.KC_URL + path; try { const response = await axios.post(url, sendData, { headers: { // Authorization: `${token}`, "Content-Type": "application/x-www-form-urlencoded", api_key: process.env.API_KEY, }, }); return response.data; } catch (error) { throw error; } } } export default CallAPI;