2024-06-13 10:17:57 +07:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Request,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Delete,
|
|
|
|
|
Patch,
|
|
|
|
|
Route,
|
|
|
|
|
Security,
|
|
|
|
|
Tags,
|
|
|
|
|
Path,
|
|
|
|
|
} from "tsoa";
|
|
|
|
|
import axios from "axios";
|
2024-09-27 23:44:47 +07:00
|
|
|
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";
|
2024-06-13 10:17:57 +07:00
|
|
|
|
|
|
|
|
class CallAPI {
|
2024-09-27 23:44:47 +07:00
|
|
|
private profileRepo = AppDataSource.getRepository(Profile);
|
|
|
|
|
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
|
|
|
|
|
private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory);
|
2024-06-13 10:17:57 +07:00
|
|
|
//Get
|
|
|
|
|
public async GetData(request: any, @Path() path: any) {
|
2024-09-27 23:44:47 +07:00
|
|
|
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
|
2024-07-09 17:03:09 +07:00
|
|
|
const url = process.env.API_URL + path;
|
2024-06-13 10:17:57 +07:00
|
|
|
try {
|
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
|
headers: {
|
2024-09-27 23:44:47 +07:00
|
|
|
Authorization: `${token}`.includes("Bearer "),
|
2024-06-13 10:17:57 +07:00
|
|
|
"Content-Type": "application/json",
|
2024-08-15 13:28:06 +07:00
|
|
|
api_key: process.env.API_KEY,
|
2024-06-13 10:17:57 +07:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return response.data.result;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-23 11:48:10 +07:00
|
|
|
//Get (response.data)
|
|
|
|
|
public async GetData2(request: any, @Path() path: any) {
|
2024-09-27 23:44:47 +07:00
|
|
|
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
|
2024-09-23 11:48:10 +07:00
|
|
|
const url = process.env.API_URL + path;
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
|
headers: {
|
2024-09-27 23:44:47 +07:00
|
|
|
Authorization: `${token}`.includes("Bearer "),
|
2024-09-23 11:48:10 +07:00
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
api_key: process.env.API_KEY,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return response.data;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-13 10:17:57 +07:00
|
|
|
//Post
|
|
|
|
|
public async PostData(request: any, @Path() path: any, sendData: any) {
|
2024-09-27 23:44:47 +07:00
|
|
|
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
|
2024-07-09 17:03:09 +07:00
|
|
|
const url = process.env.API_URL + path;
|
2024-06-13 10:17:57 +07:00
|
|
|
try {
|
|
|
|
|
const response = await axios.post(url, sendData, {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `${token}`,
|
|
|
|
|
"Content-Type": "application/json",
|
2024-08-15 13:28:06 +07:00
|
|
|
api_key: process.env.API_KEY,
|
2024-06-13 10:17:57 +07:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return response.data.result;
|
|
|
|
|
} catch (error) {
|
2024-09-27 23:44:47 +07:00
|
|
|
console.log(error);
|
2024-06-13 10:17:57 +07:00
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-27 16:37:42 +07:00
|
|
|
//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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-13 10:17:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default CallAPI;
|