แก้ 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;
|
let ImgUrl: any;
|
||||||
if (profile?.avatar != null && profile?.avatarName != null) {
|
if (profile?.avatar != null && profile?.avatarName != null) {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
|
.GetData(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
|
||||||
.then(async (x) => {
|
.then(async (x) => {
|
||||||
ImgUrl = x.downloadUrl;
|
ImgUrl = x.downloadUrl;
|
||||||
})
|
})
|
||||||
|
|
@ -287,7 +287,7 @@ export class ProfileController extends Controller {
|
||||||
let ImgUrl: any;
|
let ImgUrl: any;
|
||||||
if (profiles?.avatar != null && profiles?.avatarName != null) {
|
if (profiles?.avatar != null && profiles?.avatarName != null) {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
|
.GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
|
||||||
.then(async (x) => {
|
.then(async (x) => {
|
||||||
ImgUrl = x.downloadUrl;
|
ImgUrl = x.downloadUrl;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
let ImgUrl: any;
|
let ImgUrl: any;
|
||||||
if (profile?.avatar != null && profile?.avatarName != null) {
|
if (profile?.avatar != null && profile?.avatarName != null) {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
|
.GetData(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`)
|
||||||
.then(async (x) => {
|
.then(async (x) => {
|
||||||
ImgUrl = x.downloadUrl;
|
ImgUrl = x.downloadUrl;
|
||||||
})
|
})
|
||||||
|
|
@ -297,7 +297,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
let ImgUrl: any;
|
let ImgUrl: any;
|
||||||
if (profiles?.avatar != null && profiles?.avatarName != null) {
|
if (profiles?.avatar != null && profiles?.avatarName != null) {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
|
.GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
|
||||||
.then(async (x) => {
|
.then(async (x) => {
|
||||||
ImgUrl = x.downloadUrl;
|
ImgUrl = x.downloadUrl;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,7 @@
|
||||||
import {
|
import { Path } from "tsoa";
|
||||||
Controller,
|
|
||||||
Request,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Delete,
|
|
||||||
Patch,
|
|
||||||
Route,
|
|
||||||
Security,
|
|
||||||
Tags,
|
|
||||||
Path,
|
|
||||||
} from "tsoa";
|
|
||||||
import axios from "axios";
|
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 {
|
class CallAPI {
|
||||||
private profileRepo = AppDataSource.getRepository(Profile);
|
|
||||||
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
|
|
||||||
private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory);
|
|
||||||
//Get
|
//Get
|
||||||
public async GetData(request: any, @Path() path: any) {
|
public async GetData(request: any, @Path() path: any) {
|
||||||
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
|
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
|
||||||
|
|
@ -33,7 +9,7 @@ class CallAPI {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `${token}`.includes("Bearer "),
|
Authorization: `${token}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
api_key: process.env.API_KEY,
|
api_key: process.env.API_KEY,
|
||||||
},
|
},
|
||||||
|
|
@ -43,23 +19,6 @@ class CallAPI {
|
||||||
throw 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
|
//Post
|
||||||
public async PostData(request: any, @Path() path: any, sendData: any) {
|
public async PostData(request: any, @Path() path: any, sendData: any) {
|
||||||
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
|
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue