แก้ call api
This commit is contained in:
parent
32b50c905c
commit
ed537aa72f
3 changed files with 6 additions and 47 deletions
|
|
@ -1,31 +1,7 @@
|
|||
import {
|
||||
Controller,
|
||||
Request,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Path,
|
||||
} from "tsoa";
|
||||
import { 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 ", "");
|
||||
|
|
@ -33,7 +9,7 @@ class CallAPI {
|
|||
try {
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
Authorization: `${token}`.includes("Bearer "),
|
||||
Authorization: `${token}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
|
|
@ -43,23 +19,6 @@ class CallAPI {
|
|||
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 ", "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue