แก้ call api
This commit is contained in:
parent
32b50c905c
commit
ed537aa72f
3 changed files with 6 additions and 47 deletions
|
|
@ -136,7 +136,7 @@ export class ProfileController extends Controller {
|
|||
let ImgUrl: any;
|
||||
if (profile?.avatar != null && profile?.avatarName != null) {
|
||||
await new CallAPI()
|
||||
.GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
|
||||
.GetData(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
|
||||
.then(async (x) => {
|
||||
ImgUrl = x.downloadUrl;
|
||||
})
|
||||
|
|
@ -287,7 +287,7 @@ export class ProfileController extends Controller {
|
|||
let ImgUrl: any;
|
||||
if (profiles?.avatar != null && profiles?.avatarName != null) {
|
||||
await new CallAPI()
|
||||
.GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
|
||||
.GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
|
||||
.then(async (x) => {
|
||||
ImgUrl = x.downloadUrl;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
let ImgUrl: any;
|
||||
if (profile?.avatar != null && profile?.avatarName != null) {
|
||||
await new CallAPI()
|
||||
.GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
|
||||
.GetData(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
|
||||
.then(async (x) => {
|
||||
ImgUrl = x.downloadUrl;
|
||||
})
|
||||
|
|
@ -297,7 +297,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
let ImgUrl: any;
|
||||
if (profiles?.avatar != null && profiles?.avatarName != null) {
|
||||
await new CallAPI()
|
||||
.GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
|
||||
.GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
|
||||
.then(async (x) => {
|
||||
ImgUrl = x.downloadUrl;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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